{"id":14964332,"url":"https://github.com/aaronransley/nuxt-winston-log","last_synced_at":"2025-04-05T13:02:32.384Z","repository":{"id":35857519,"uuid":"188490610","full_name":"aaronransley/nuxt-winston-log","owner":"aaronransley","description":"Nuxt module for logging SSR errors using winston","archived":false,"fork":false,"pushed_at":"2024-10-24T22:21:08.000Z","size":78,"stargazers_count":45,"open_issues_count":5,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-30T00:43:58.964Z","etag":null,"topics":["error-handling","logging","nuxt","nuxt-module","nuxtjs","winston"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aaronransley.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-24T21:39:49.000Z","updated_at":"2023-12-01T07:10:28.000Z","dependencies_parsed_at":"2024-11-15T21:34:16.122Z","dependency_job_id":"93fc4dd8-cd0f-4184-9537-4784f85d78e5","html_url":"https://github.com/aaronransley/nuxt-winston-log","commit_stats":{"total_commits":34,"total_committers":3,"mean_commits":"11.333333333333334","dds":0.08823529411764708,"last_synced_commit":"f7f4d707b2f2c0ba4dfc6727ebeb0afb383cddd0"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronransley%2Fnuxt-winston-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronransley%2Fnuxt-winston-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronransley%2Fnuxt-winston-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronransley%2Fnuxt-winston-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aaronransley","download_url":"https://codeload.github.com/aaronransley/nuxt-winston-log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247339148,"owners_count":20923013,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["error-handling","logging","nuxt","nuxt-module","nuxtjs","winston"],"created_at":"2024-09-24T13:32:59.924Z","updated_at":"2025-04-05T13:02:32.360Z","avatar_url":"https://github.com/aaronransley.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nuxt-winston-log\n\nA Nuxt `2.x` module to add [winston](https://github.com/winstonjs/winston)-powered logging to your Nuxt application.\n\n* **Works with**: Nuxt `@2.x` projects running on a server (e.g. universal, SSR mode).\n* **Does not support**: Statically generated Nuxt projects (i.e. SSG via `nuxt generate`).\n\n\u003cimg alt=\"Winston + Nuxt logo\" src=\"https://raw.githubusercontent.com/aaronransley/nuxt-winston-log/master/icon.png\" width=\"128\" /\u003e\n\n# Introduction\n\nBy default the following events are captured:\n\n1. `error` level: SSR errors via Nuxt middleware hooks\n3. `info` level: Basic access logs for `serverMiddleware` endpoints + pages in your Nuxt app\n\nAll logs captured include a bit of additional metadata pulled from the [Node.js `request` object](https://nodejs.org/dist/latest-v10.x/docs/api/http.html#http_class_http_incomingmessage):\n\n```js\n{\n  url: 'https://cool.net',\n  method: 'GET',\n  headers: {\n    'X-Plumbus': \"36f7b241-2910-4439-8671-749fc77dc213\"\n  }\n}\n```\n\nLogs are output at `./logs/{NODE_ENV}.log` by default. They are created in [JSON Lines](http://jsonlines.org/) format.\n\n# Installation\n\n1. Install npm package\n\n```sh\n$ yarn add nuxt-winston-log # or npm i nuxt-winston-log\n```\n\n2. Edit your `nuxt.config.js` file to add module\n\n```js\n{\n  modules: ['nuxt-winston-log']\n}\n```\n\n3. Change options using the `winstonLog` key as needed. See Usage section for details.\n\n# Usage\n\n1. By default, `nuxt-winston-log` exposes some basic options for common needs. Internally, these options are used to create a basic [Logger instance](https://github.com/winstonjs/winston#creating-your-own-logger) and wire up middleware.\n\n    The default values are:\n\n    ```js\n    // ...\n    {\n      // Path that log files will be created in.\n      // Change this to keep things neat.\n      logPath: './logs',\n\n      // Name of log file.\n      // Change this to keep things tidy.\n      logName: `${process.env.NODE_ENV}.log`,\n\n      // Setting to determine if filesystem is accessed to auto-create logPath.\n      // Set this to `false` for non-filesystem based logging setups.\n      autoCreateLogPath: true,\n\n      // Setting to determine if default logger instance is created for you.\n      // Set this to `false` and provide `loggerOptions` (usage item #3) to\n      // completely customize the logger instance (formatting, transports, etc.)\n      useDefaultLogger: true,\n\n      // Settings to determine if default handlers should be\n      // registered for requests and errors respectively.\n      // Set to `true` to skip request logging (level: info).\n      skipRequestMiddlewareHandler: false,\n      // Set to `true` to skip error logging (level: error).\n      skipErrorMiddlewareHandler: false\n    }\n    // ...\n    ```\n\n2. To customize the [File Transport instance](https://github.com/winstonjs/winston/blob/master/docs/transports.md#file-transport), pass options to the `transportOptions` key:\n\n    Example in your apps `~/nuxt.config.js` file:\n    ```js\n    import path from 'path'\n    const logfilePath = path.resolve(process.cwd(), './logs', `${process.env.NODE_ENV}.log`)\n\n    export default {\n      // Configure nuxt-winston-log module\n      winstonLog: {\n        transportOptions: {\n          filename: logfilePath\n        }\n      }\n    }\n    ```\n\n3. To customize the [Logger instance](https://github.com/winstonjs/winston#creating-your-own-logger), set `useDefaultLogger` option to `false`, and make sure you provide a custom set of `loggerOptions` to be passed to [Winston's `createLogger`](https://github.com/winstonjs/winston#creating-your-own-logger) under the hood:\n\n    Example in your apps `~/nuxt.config.js` file:\n    ```js\n    // Note imports from winston core for transports, formatting helpers, etc.\n    import { format, transports } from 'winston'\n    const { combine, timestamp, label, prettyPrint } = format\n\n    export default {\n      // Configure nuxt-winston-log module\n      winstonLog: {\n        useDefaultLogger: false,\n        loggerOptions: {\n          format: combine(\n            label({ label: 'Custom Nuxt logging!' }),\n            timestamp(),\n            prettyPrint()\n          ),\n          transports: [new transports.Console()]\n        }\n      }\n    }\n    ```\n\n4. To disable automatic creation of the `logPath` directory, set `autoCreateLogPath` option to `false`:\n\n    Example in your apps `~/nuxt.config.js` file:\n    ```js\n    // ...\n    export default {\n      // Configure nuxt-winston-log module\n      winstonLog: {\n        autoCreateLogPath: false\n      }\n    }\n    // ...\n    ```\n\n5. To access the winston logger instance from within Nuxt lifecycle areas, use the `$winstonLog` key from the Nuxt `context` object. **Note:** This is only available for server-side executions. For example, because `asyncData` is an isomorphic function in Nuxt, you will need to guard `$winstonLog` access with something like `if (process.server) { ... }`\n\n    Example `nuxtServerInit` in your apps `~/store/index.js`:\n    ```js\n    // ...\n    export const actions = {\n      async nuxtServerInit({ store, commit }, { req, $winstonLog }) {\n        $winstonLog.info(`x-forwarded-host: ${req.headers['x-forwarded-host']}`)\n      }\n    }\n    // ...\n    ```\n\n    Example `asyncData` in your apps `~/pages/somepage.vue`:\n    ```js\n    // ...\n    asyncData(context) {\n      if (process.server) {\n        context.$winstonLog.info('Hello from asyncData on server')\n      }\n    }\n    // ...\n    ```\n\n6. To disable default request and error logging behaviors, the `skipRequestMiddlewareHandler` and `skipErrorMiddlewareHandler` options can be set to `true`. For more information on what these handlers do out of the box, see the source at the [bottom of the `~/index.js` file](https://github.com/aaronransley/nuxt-winston-log/blob/master/index.js#L58-L89).\n\n    Example in your apps `~/nuxt.config.js` file:\n    ```js\n    // ...\n    export default {\n      // Configure nuxt-winston-log module\n      winstonLog: {\n        skipRequestMiddlewareHandler: true,\n        skipErrorMiddlewareHandler: true\n      }\n    }\n    // ...\n    ```\n    \n    Adding your own middleware handlers to Nuxt is outside the scope of this documentation, but can be accomplished using [a custom module of your own](https://nuxtjs.org/docs/2.x/directory-structure/modules#write-your-own-module).\n    \n# Using `process.winstonLog` in a Nuxt Module\n\nBecause modules are executed sequentially, any additional [Nuxt modules](https://nuxtjs.org/docs/2.x/directory-structure/modules#write-your-own-module) should be loaded _after the `nuxt-winston-log` module_. You can then access the logger instance via `process.winstonLog` as needed.\n\n# [Changelog](./CHANGELOG.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronransley%2Fnuxt-winston-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faaronransley%2Fnuxt-winston-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronransley%2Fnuxt-winston-log/lists"}