{"id":22796287,"url":"https://github.com/makerxstudio/node-winston","last_synced_at":"2025-03-30T18:14:59.276Z","repository":{"id":177167824,"uuid":"530943730","full_name":"MakerXStudio/node-winston","owner":"MakerXStudio","description":"A set of MakerX winston formats, console transport and logger creation functions","archived":false,"fork":false,"pushed_at":"2024-02-14T19:03:47.000Z","size":411,"stargazers_count":0,"open_issues_count":8,"forks_count":0,"subscribers_count":13,"default_branch":"main","last_synced_at":"2024-03-15T03:08:28.906Z","etag":null,"topics":["logging","npm","package","typescript","winston"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MakerXStudio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2022-08-31T05:14:01.000Z","updated_at":"2023-06-29T03:01:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"d4a7af85-b60d-4d84-ac5f-f548f4f019ed","html_url":"https://github.com/MakerXStudio/node-winston","commit_stats":null,"previous_names":["makerxstudio/node-winston"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MakerXStudio%2Fnode-winston","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MakerXStudio%2Fnode-winston/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MakerXStudio%2Fnode-winston/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MakerXStudio%2Fnode-winston/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MakerXStudio","download_url":"https://codeload.github.com/MakerXStudio/node-winston/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246358321,"owners_count":20764366,"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":["logging","npm","package","typescript","winston"],"created_at":"2024-12-12T05:11:49.046Z","updated_at":"2025-03-30T18:14:59.260Z","avatar_url":"https://github.com/MakerXStudio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node Winston\n\nA set of [winston](https://github.com/winstonjs/winston) [formats](https://github.com/winstonjs/winston#formats), console transport and logger creation functions.\n\nSimplifies using winston logging and provides coloured YAML log output for local development.\n\n## Creating a Logger\n\nThe `createLogger` function combines `omitFormat`, `omitNilFormat` and optionally `prettyConsoleFormat` together to configure the `Console` transport for the returned logger.\n\n| Option           | Description                                                                                                                                                                                                                    |\n| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `consoleFormat`  | Either `pretty` (useful for local development) or `json` (default)                                                                                                                                                             |\n| `consoleOptions` | The `ConsoleTransportOptions` passed into the `Console` transport, useful for setting `silent`, e.g. to switch off output during test runs, per-transport `level` etc.                                                         |\n| `loggerOptions`  | The `LoggerOptions` passed into the `Logger`, useful for the `level`, `defaultMeta` and other customisations.                                                                                                                  |\n| `loggerOptions`  | The `LoggerOptions` passed into the `Logger`, useful for the `level`, `defaultMeta` and other customisations.                                                                                                                  |\n| `omitPaths`      | Paths of fields you wish to omit form logging. For example, during local development you may wish to hide values from `defaultMeta`, e.g. user context which would be omitted in every log entry and irrelevent for local dev. |\n| `transports`     | Extra `Transport`s you wish to add to the logger.                                                                                                                                                                              |\n\nAt MakerX we generally use config files to control logging output across local development and deployed environments:\n\nlogger.ts\n\n```ts\nimport { isLocalDev } from '@makerxstudio/node-common'\nimport { createLogger } from '@makerxstudio/node-winston'\nimport config from 'config'\n\nconst logger = createLogger({\n  consoleFormat: isLocalDev ? 'pretty' : 'json',\n  consoleOptions: config.get('logging.consoleOptions'),\n  loggerOptions: config.get('logging.loggerOptions'),\n  omitPaths: config.get('logging.omitPaths'),\n})\n\nexport default logger\n```\n\nThis would translate into different runtime configurations:\n\n```ts\n// local development logger would be created something like...\nconst logger = createLogger({\n  consoleFormat: 'pretty',\n  loggerOptions: {\n    defaultMeta: {\n      service: 'my-application-name',\n    },\n    level: 'verbose',\n  },\n  omitPaths: ['service'], // defaultMeta.service is set in the default (all environments) config, localdev config strips this from output\n})\n\n// deployed environment logger would be created something like...\nconst logger = createLogger({\n  consoleFormat: 'json',\n  loggerOptions: {\n    defaultMeta: {\n      service: 'my-application-name',\n    },\n    level: 'info',\n  },\n})\n\n// integration tests could silence noisy console output by setting process.env.SILENT_CONSOLE to 'true'\nconst logger = createLogger({\n  consoleOptions: {\n    silent: true,\n  },\n})\n```\n\n## Transports\n\nThe `createLogger` method creates (only) a `Console` transport.\n\nIf you wish to add [other transports](https://github.com/winstonjs/winston/blob/master/docs/transports.md), pass them in via the `transports` option, e.g.\n\n```ts\nconst logger = createLogger({\n  transports: [\n    new DailyRotateFile({\n      level: 'info',\n      filename: 'application-%DATE%.log',\n      datePattern: 'YYYY-MM-DD-HH',\n      zippedArchive: true,\n      maxSize: '20m',\n      maxFiles: '14d',\n    }),\n  ],\n})\n```\n\n## Formats\n\n`createLogger` applies some default behaviour, chaining `omitNilFormat` and `omitFormat` in front of the final json or coloured YAML format.\n\n- `omitNilFormat` removes null or undefined values from output\n- `omitFormat` removes values by path using [lodash omit](https://lodash.com/docs/4.17.15#omit) (see docs for path specification)\n- `prettyConsoleFormat` applies the `colorize` and `timestamp` formats before formatting logs as coloured YAML\n\nIf you wish to add additional formats, pass them in via the `consoleFormats` option.\n\n### Error serialization\n\nThe `Error` class's `message` and `stack` properties [are not enumerable](https://stackoverflow.com/questions/18391212/is-it-not-possible-to-stringify-an-error-using-json-stringify); the output of `JSON.stringify(new Error('message'))` is `'{}'`.\n\nWinston has some special handling, so that when an error is the first or second argument, message and stack props are logged:\n\n```ts\nlogger.log(new Error('cause')) // {message: 'cause', stack: ...}\nlogger.log('message', new Error('cause')) // {message: 'message cause', stack: ...}\n```\n\nHowever, when errors are nested in structured log data, message and stack props are lost:\n\n```ts\ncatch (error) {\n  logger.log('message', { info, error }) // {message: 'message', error: {}}\n}\n```\n\nWinston [logform](https://github.com/winstonjs/logform) uses [safe-stable-stringify](https://www.npmjs.com/package/safe-stable-stringify) which supports a `replacer`, similar to `JSON.stringify`.\n\nIn `createLogger` we use `serializableErrorReplacer` via the JSON format options to ensure that the `message` and `stack` properties of errors are serialized to error logs:\n\n```ts\nformat.json({ replacer: serializableErrorReplacer })\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakerxstudio%2Fnode-winston","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmakerxstudio%2Fnode-winston","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakerxstudio%2Fnode-winston/lists"}