{"_id":"@amida-tech/winston-json-formatter","_rev":"1-8b2385403490f5d30058c1c644633d02","name":"@amida-tech/winston-json-formatter","dist-tags":{"latest":"0.10.2"},"versions":{"0.10.1":{"name":"@amida-tech/winston-json-formatter","description":"A Winston JSON Formatter","main":"lib/index.js","repository":{"type":"git","url":"git+https://github.com/amida-tech/winston-json-formatter.git"},"license":"Apache-2.0","version":"0.10.1","publishConfig":{"access":"public"},"scripts":{"build":"babel src --out-dir lib","clean":"rimraf coverage lib","lint":"eslint src/ test/","prepublish":"yarn build","test":"jest","test:coverage":"yarn test --coverage"},"keywords":["formatter","logging","winston"],"engines":{"node":">=8.10.0","npm":">=5.6.0","yarn":">=1.5.1"},"author":{"name":"Morgan Peters","email":"morgan@amida.com"},"contributors":[{"name":"Ryan Harrison","email":"ryan@amida.com"},{"name":"Aaron Houlihan","email":"aaron@amida.com"}],"dependencies":{"lodash":"^4.17.21","os":"^0.1.2","winston":"^3.8.1"},"devDependencies":{"@babel/cli":"^7.18.9","@babel/core":"^7.18.9","@babel/node":"^7.18.9","@babel/preset-env":"^7.18.9","@chrisalderson/winston-spy":"^1.0.2","babel-jest":"^28.1.3","eslint":"^8.20.0","eslint-config-airbnb-base":"^15.0.0","eslint-plugin-import":"^2.26.0","jest":"^28.1.3","regenerator-runtime":"^0.13.9","rimraf":"^3.0.2","sinon":"^14.0.0"},"jest":{"automock":false,"bail":false,"verbose":true,"testMatch":["**/Tests/**/*.js","**/?(*.)(spec|test|integration).js?(x)"],"modulePathIgnorePatterns":["/node_modules/","/coverage/","/dist/"]},"private":false,"gitHead":"6a88b94d472b99c54b649e46bf9762be5e349a54","bugs":{"url":"https://github.com/amida-tech/winston-json-formatter/issues"},"homepage":"https://github.com/amida-tech/winston-json-formatter#readme","_id":"@amida-tech/winston-json-formatter@0.10.1","_nodeVersion":"16.14.2","_npmVersion":"8.12.1","dist":{"integrity":"sha512-9nD8NtxTKUZKxzXPlioxhsBLnatq5nHzMgBpFEGFWGHeqqipKJmDz2fmXMmMHm9KWd97z/GGdr0gckJHP6NEeQ==","shasum":"bd723745e31dc8319e4d2f547532652e1bc1ba23","tarball":"https://registry.npmjs.org/@amida-tech/winston-json-formatter/-/winston-json-formatter-0.10.1.tgz","fileCount":14,"unpackedSize":235230,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEB1JR/qNd+rdRb8UraUS/P0ec+AuAFVPaT4tUTtQ/YHAiAn+J4nHuy/lTgkKJiPKK2rdqGcmWPabc4X4szmy1/EZA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi2Xk3ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqzzg//anpjJOQQzYbMBW4zo2aj5Hy+yTRet6hlCSTKxUwxO3AXQqXy\r\na5PSr6rRPgHbaSLqbUmF+wpb0cjsaWZD2aDqlIcLjg6SYIDbzs9KLaRKeEdZ\r\n/J7VH5xKLqp2wVg0IKbT7z3g0eh1ZVp3c3a9WNb7yZfqPkEZpM8TT3BzH/or\r\nOnpT+bvHXJPGOUe01FZMOE/Y++7ldzzQHTI4k+sxhdhn+w7IgM24asDsm8Or\r\ncduUUDkZnp9Ntobr8BSmj3E1WnVxeoV4bZd4Ou5MfzMd5KWzbQud1cUQM2mE\r\nt9+B95ceUIWE3P26yM/yJ2x/xJMoaH8S8iuj9cyXcM8qnrCIsvAqDPgGoNwk\r\n4QWmbP2gbv1zwYeP7L2HWGmIA5jnJopvtVqA5chFITI8EqXp86K01BP44Xnu\r\nGKbs5a99Hf0M0tJmnJygO+se5IZymT2rulZyDg3DNaBzzHaFQm15kIAgrGG5\r\nM/ieVm+SbuJl8IEOJl5aNapyi8PTuOOvFfh+/XuuFkQiaIN6vFGXpHu2N3c7\r\ndNtblJe2ZecN1ef0JZEVVFpSm6hqNPZ5n+827bvfeqEI9AzViskQrB6xd3c0\r\neT4eO66gYl3aLMJW+ChxoNg2EmOF3SepFc/HPupYhKwg73fwUOcAp0aDsKQ8\r\nmUzhkZVeH2ald6frMdD2MXFKvXRRnoD3In8=\r\n=RCi6\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"manhydra","email":"marc.sylvestre@manhydra.com"},"directories":{},"maintainers":[{"name":"manhydra","email":"marc.sylvestre@manhydra.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/winston-json-formatter_0.10.1_1658419511320_0.7977380756849444"},"_hasShrinkwrap":false},"0.10.2":{"name":"@amida-tech/winston-json-formatter","description":"A Winston JSON Formatter","main":"lib/index.js","repository":{"type":"git","url":"git+https://github.com/amida-tech/winston-json-formatter.git"},"license":"Apache-2.0","version":"0.10.2","publishConfig":{"access":"public"},"scripts":{"build":"babel src --out-dir lib","clean":"rimraf coverage lib","lint":"eslint src/ test/","prepublish":"yarn build","test":"jest","test:coverage":"yarn test --coverage"},"keywords":["formatter","logging","winston"],"engines":{"node":">=18.0.0","yarn":">=1.22.0"},"author":{"name":"Morgan Peters","email":"morgan@amida.com"},"contributors":[{"name":"Ryan Harrison","email":"ryan@amida.com"},{"name":"Aaron Houlihan","email":"aaron@amida.com"},{"name":"Marc Sylvestre","email":"marc.sylvestre@manhydra.com"}],"dependencies":{"lodash":"^4.17.21","os":"^0.1.2","winston":"^3.10.0"},"devDependencies":{"@babel/cli":"^7.22.9","@babel/core":"^7.22.9","@babel/node":"^7.22.6","@babel/preset-env":"^7.22.9","@chrisalderson/winston-spy":"^1.0.2","babel-jest":"^29.6.2","eslint":"^8.46.0","eslint-config-airbnb-base":"^15.0.0","eslint-plugin-import":"^2.28.0","jest":"^29.6.2","regenerator-runtime":"^0.13.11","rimraf":"^5.0.1","sinon":"^15.2.0"},"jest":{"automock":false,"bail":false,"verbose":true,"testMatch":["**/Tests/**/*.js","**/?(*.)(spec|test|integration).js?(x)"],"modulePathIgnorePatterns":["/node_modules/","/coverage/","/dist/"]},"private":false,"gitHead":"dba016d86461791265e69af37f636a984710a66b","bugs":{"url":"https://github.com/amida-tech/winston-json-formatter/issues"},"homepage":"https://github.com/amida-tech/winston-json-formatter#readme","_id":"@amida-tech/winston-json-formatter@0.10.2","_nodeVersion":"18.17.0","_npmVersion":"9.6.7","dist":{"integrity":"sha512-zVS2Mp1rRdEo0hy8L9kM15guugUKmw5/zCOkrN4aL2GQZKTfiRw5w8Sg9rt9fq9EeXfPu1haRmoxzRbL5Luy2w==","shasum":"ed9905c268021793f9b4d301e05d9d282bf843c5","tarball":"https://registry.npmjs.org/@amida-tech/winston-json-formatter/-/winston-json-formatter-0.10.2.tgz","fileCount":14,"unpackedSize":235291,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHKiUCFEBDT26HYStjtHeBCS3lkpvwkykHArKxG/OYvwAiEAzTHTiyw2cjn5gd90Dv7jN2+K9Ff/8ZSffvm3JYQYOSo="}]},"_npmUser":{"name":"manhydra","email":"marc.sylvestre@manhydra.com"},"directories":{},"maintainers":[{"name":"manhydra","email":"marc.sylvestre@manhydra.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/winston-json-formatter_0.10.2_1690820263719_0.14036918708816803"},"_hasShrinkwrap":false}},"time":{"created":"2022-07-21T16:05:11.230Z","0.10.1":"2022-07-21T16:05:11.574Z","modified":"2023-07-31T16:17:44.073Z","0.10.2":"2023-07-31T16:17:43.947Z"},"maintainers":[{"name":"manhydra","email":"marc.sylvestre@manhydra.com"}],"description":"A Winston JSON Formatter","homepage":"https://github.com/amida-tech/winston-json-formatter#readme","keywords":["formatter","logging","winston"],"repository":{"type":"git","url":"git+https://github.com/amida-tech/winston-json-formatter.git"},"contributors":[{"name":"Ryan Harrison","email":"ryan@amida.com"},{"name":"Aaron Houlihan","email":"aaron@amida.com"},{"name":"Marc Sylvestre","email":"marc.sylvestre@manhydra.com"}],"author":{"name":"Morgan Peters","email":"morgan@amida.com"},"bugs":{"url":"https://github.com/amida-tech/winston-json-formatter/issues"},"license":"Apache-2.0","readme":"# Winston JSON Formatter\n\n[![npm (tag)](https://img.shields.io/npm/v/@amida-tech/winston-json-formatter/latest.svg)](https://www.npmjs.com/package/@amida-tech/winston-json-formatter)\n[![Known Vulnerabilities](https://snyk.io/test/npm/@amida-tech/winston-json-formatter/badge.svg)](https://snyk.io/test/npm/@amida-tech/winston-json-formatter)\n[![Jenkins CI](https://jenkins.amida.com/buildStatus/icon?job=Winston%20JSON%20Formatter%20Tests)](https://jenkins.amida.com/job/Winston%20JSON%20Formatter%20Tests/)\n\nA json and console formatter for [winston@3](https://github.com/winstonjs/winston).\n\n## Quickstart:\n\n```javascript\nconst { createLogger, transports } = require('winston');\nconst { configuredFormatter } = require('winston-json-formatter');\n\n// Create Logger and configure options.\n\nconst logger = createLogger({ \n    level: 'silly',\n    transports: [\n        new (transports.Console)(),\n    ],\n});\nconst options = { \n    service: 'test-service', \n    logger: 'Winston-JSON-Formatter',\n    version: '1.0.0', \n    typeFormat: 'json'\n};\n\n// set winston logger format and print logs.\nlogger.format = configuredFormatter(options);\n\n// Availale log levels\nlogger.error('message');\nlogger.warn('message');\nlogger.info('message');\nlogger.verbose('message');\nlogger.debug('message');\nlogger.silly('message');\n\n// Error Objects can be logged directly\nerr = new Error('Heroic BSoD')\nlogger.error(err)\n```\n\n## Configuration\nENV\n- `NODE_ENV=dev` || `NODE_ENV=development` => `options.typeFormat=console`\n- Otherwise, `options.typeFormat=json` (default)\n\n| Option               | Default                       | Type                    |\n| -------------------- | ----------------------------- | ----------------------- |\n| `options.typeFormat` | Default: 'json'               | Enum: 'console', 'json' |\n| `options.hostname`   | Default: `os.hostname()`      | String                  |\n| `options.logger`     | Default: 'application-logger' | String                  |\n| `options.node_env`   | Default: `ENV NODE_ENV`       | String                  |\n| `options.service`    |                               | String                  |\n| `options.version`    |                               | String                  |\n\n## Test\n```bash\nyarn install\nyarn test\nyarn test:coverage\n```\n\n## Output\n\n### Json logging\n```javascript\n\n> const err = new Error('error message');\n> const err.code = 'SOME_CODE';\n> // The colon and space here are recommended due to this bug in winston (https://github.com/winstonjs/winston/issues/1634)\n> logger.info('log message: ', err);\n{\n  \"service\": \"test-service\",\n  \"logger\": \"Winston-JSON-Formatter\",\n  \"hostname\": \"host\",\n  \"level\": \"info\",\n  \"msg\": \"log message: error message\",\n  \"meta\": {\n    \"service\": {\n      \"version\": \"1.0.0\",\n      \"node_env\": \"\"\n    },\n    \"logger\": {\n      \"time\": \"2018-11-28T02:52:06.700Z\"\n    },\n    \"event\": {\n      \"code\": \"SOME_CODE\"\n    }\n  },\n  \"err\": {\n    // There should be a member `\"name\": \"Error\"` here if it were not for winston bug (https://github.com/winstonjs/winston/issues/1635)\n    \"stack\": \"THE_ERROR_STACK\"\n  }\n}\n\n> const err = new Error('error message');\n> const err.code = 'SOME_CODE';\n> logger.info(err, {foo: 'bar', baz: 'qux'});\n{\n  \"service\": \"test-service\",\n  \"logger\": \"Winston-JSON-Formatter\",\n  \"hostname\": \"host\",\n  \"level\": \"info\",\n  \"msg\": \"message: error message\",\n  \"meta\": {\n    \"service\": {\n      \"version\": \"1.0.0\",\n      \"node_env\": \"\"\n    },\n    \"logger\": {\n      \"time\": \"2018-11-28T02:52:06.700Z\"\n    },\n    \"event\": {\n      \"foo\": \"bar\",\n      \"baz\": \"qux\",\n      \"code\": \"SOME_CODE\"\n    }\n  },\n  \"err\": {\n    \"name\": \"Error\"\n    \"stack\": \"THE_ERROR_STACK\"\n  }\n}\n```\n\n### Console logging\n![console log style](docs/console-log-example.png)\n\n\n```sh\n# Generally, the format is:\n\n# timestamp level message\n# stack_if_one_exists\n# {\n#   other: 'members-if-they-exist'\n# }\n\n# > logger.info(\"log message\") ------------------------------------------------------------------ \n2019-04-12T02:10:11.091Z info log message  \n# ----\n\n\n# > logger.info(new Error(\"error message\")) ------------------------------------------------------------------ \n2019-04-12T02:10:11.094Z info error message \nError: error message\n    at Object.<anonymous> (/Users/houli/docs/gitrepos/amida-tech/winston-json-formatter/experiment.js:38:13)\n    at Module._compile (module.js:653:30)\n    at Object.Module._extensions..js (module.js:664:10)\n    at Module.load (module.js:566:32)\n    at tryModuleLoad (module.js:506:12)\n    at Function.Module._load (module.js:498:3)\n    at Function.Module.runMain (module.js:694:10)\n    at startup (bootstrap_node.js:204:16)\n    at bootstrap_node.js:625:3 \n# ----\n\n\n# > logger.info(\"message\", new Error(\"error message\")) ------------------------------------------------------------------ \n2019-04-12T02:10:11.095Z info log messageerror message \nError: error message\n    at Object.<anonymous> (/Users/houli/docs/gitrepos/amida-tech/winston-json-formatter/experiment.js:41:28)\n    at Module._compile (module.js:653:30)\n    at Object.Module._extensions..js (module.js:664:10)\n    at Module.load (module.js:566:32)\n    at tryModuleLoad (module.js:506:12)\n    at Function.Module._load (module.js:498:3)\n    at Function.Module.runMain (module.js:694:10)\n    at startup (bootstrap_node.js:204:16)\n    at bootstrap_node.js:625:3 \n# ----\n\n\n# > logger.info({a: \"a\", b: \"b\"}) ------------------------------------------------------------------ \n2019-04-12T02:10:11.095Z info \n{\n  \"a\": \"a\",\n  \"b\": \"b\"\n}  \n# ----\n\n\n# > logger.info(new Error(\"error message\"), { a: \"a\", b: \"b\" } ) ------------------------------------------------------------------ \n2019-04-12T02:10:11.096Z info error message \nError: error message\n    at Object.<anonymous> (/Users/houli/docs/gitrepos/amida-tech/winston-json-formatter/experiment.js:47:13)\n    at Module._compile (module.js:653:30)\n    at Object.Module._extensions..js (module.js:664:10)\n    at Module.load (module.js:566:32)\n    at tryModuleLoad (module.js:506:12)\n    at Function.Module._load (module.js:498:3)\n    at Function.Module.runMain (module.js:694:10)\n    at startup (bootstrap_node.js:204:16)\n    at bootstrap_node.js:625:3 \n{\n  \"a\": \"a\",\n  \"b\": \"b\"\n}\n# ----\n\n\n# Logging an object that is not an Error that does have a member named stack will confuse the logger. This is unavoidable.\n# > logger.info({ name: \"some name\", stack: \"some stack\" }) ------------------------------------------------------------------ \n2019-04-12T02:10:11.096Z info \n{\n  \"name\": \"some name\",\n  \"stack\": \"some stack\"\n} \nsome stack \n# ----\n\n\n# Logging an object that is not an Error that does have a member named stack will confuse the logger. This is unavoidable.\n# > logger.info(\"message\", { name: \"some name\", stack: \"some stack\" }) ------------------------------------------------------------------ \n2019-04-12T02:10:11.096Z info message \nsome stack \n# ----\n\n\n# > logger.info(\"message\", { a: \"a\", b: \"b\" }) ------------------------------------------------------------------ \n2019-04-12T02:10:11.096Z info message  \n{\n  \"a\": \"a\",\n  \"b\": \"b\"\n}\n# ----\n\n\n# > const err = new Error(\"error message\"); err.code = \"SOME_CODE\"; logger.info(\"message\", new Error(\"error message\")) ------------------------------------------------------------------ \n2019-04-12T02:10:11.097Z info messageError A \nError: Error A\n    at Object.<anonymous> (/Users/houli/docs/gitrepos/amida-tech/winston-json-formatter/experiment.js:58:14)\n    at Module._compile (module.js:653:30)\n    at Object.Module._extensions..js (module.js:664:10)\n    at Module.load (module.js:566:32)\n    at tryModuleLoad (module.js:506:12)\n    at Function.Module._load (module.js:498:3)\n    at Function.Module.runMain (module.js:694:10)\n    at startup (bootstrap_node.js:204:16)\n    at bootstrap_node.js:625:3 \n{\n  \"code\": \"SOME_CODE\"\n}\n# ----\n\n\n# > const err = new Error(\"error message\"); err.code = \"SOME_CODE\"; logger.info(new Error(\"error message\")) ------------------------------------------------------------------ \n2019-04-12T02:10:11.097Z info Error A \nError: Error A\n    at Object.<anonymous> (/Users/houli/docs/gitrepos/amida-tech/winston-json-formatter/experiment.js:58:14)\n    at Module._compile (module.js:653:30)\n    at Object.Module._extensions..js (module.js:664:10)\n    at Module.load (module.js:566:32)\n    at tryModuleLoad (module.js:506:12)\n    at Function.Module._load (module.js:498:3)\n    at Function.Module.runMain (module.js:694:10)\n    at startup (bootstrap_node.js:204:16)\n    at bootstrap_node.js:625:3 \n{\n  \"code\": \"SOME_CODE\"\n}\n# ----\n\n\n# > const err = new Error(\"error message\"); err.code = \"SOME_CODE\"; logger.info(new Error(\"error message\"), { a: \"a\", b: \"b\" } ) ------------------------------------------------------------------ \n2019-04-12T02:10:11.097Z info Error A \nError: Error A\n    at Object.<anonymous> (/Users/houli/docs/gitrepos/amida-tech/winston-json-formatter/experiment.js:58:14)\n    at Module._compile (module.js:653:30)\n    at Object.Module._extensions..js (module.js:664:10)\n    at Module.load (module.js:566:32)\n    at tryModuleLoad (module.js:506:12)\n    at Function.Module._load (module.js:498:3)\n    at Function.Module.runMain (module.js:694:10)\n    at startup (bootstrap_node.js:204:16)\n    at bootstrap_node.js:625:3 \n{\n  \"a\": \"a\",\n  \"b\": \"b\",\n  \"code\": \"SOME_CODE\"\n}\n```\n\n## Miscellaneous Goodies\n\nThis repo also provides a function to check if a particular log level is greater than the currently configured log level.\n\nExample useage:\n\n```js\n// In some service...\n\n// config.js\nmodule.exports = {\n    logLevel: 'info',\n}\n\n// FancyCustomError.js\nimport { initLogLevelGte } from 'winston-json-formatter'\nconst config = require('../config/index.js')\nconst logLevelGte = initLogLevelGte(config.logLevel)\n\nclass FancyCustomError extends Error {\n  constructor(rootErrorThatCouldHaveSecretStuffInIt, message, foo, bar) {\n    super()\n\n    this.message = message\n\n    if (logLevelGte('debug')) {\n        this.rootErrorThatCouldHaveSecretStuffInIt = rootErrorThatCouldHaveSecretStuffInIt\n    }\n  }\n}\n\n// someFile.js\nlogger.info(new FancyCustomError(err, 'Error creating user'))\n\n// When the configured log level is 'info', you would see logged only 'Error creating user', but when the configured log level is 'debug', you would see all the guts and glory.\n```\n","readmeFilename":"README.md"}