{"_id":"@revmob/logger","_rev":"65-be33d40668a6c26b6706e81b05ac4fee","name":"@revmob/logger","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.7":{"name":"@revmob/logger","version":"1.0.7","author":{"name":"Henrique Barcelos","email":"henrique.barcelos@revmob.com"},"license":"ISC","_id":"@revmob/logger@1.0.7","maintainers":[{"name":"guisouza","email":"gui_souza@me.com"},{"name":"hbarcelos","email":"rick.hjpbarcelos@gmail.com"},{"name":"revmobadmin","email":"revmobads@revmob.com"}],"dist":{"shasum":"1783aa191367f54a8ec61edcbb7b5550dc75cb44","tarball":"https://registry.npmjs.org/@revmob/logger/-/logger-1.0.7.tgz","integrity":"sha512-KUOn3ZBkRpkQXTaC/c2teOIvtRQBYljElCEnrR0D09nvchKs5EV0pe51UfuuF/FG6O8JyVRrPTld114WQTlXMA==","signatures":[{"sig":"MEYCIQDvRURHa52wIvdSqZy7bVo4dyhibyRndu9RrHqUUL9ZewIhANhq9mpWVWCEdiNILT8dVdkB3Sgd56XvyI363ntkuePH","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"dist/index.js","_from":".","module":"src/index.js","_shasum":"1783aa191367f54a8ec61edcbb7b5550dc75cb44","gitHead":"b6759c115398d33072fa954a865bbcc1054cbb3c","scripts":{"lint":"eslint ./src","test":"echo 'No tests yet :('","build":"babel src/ -d dist/","clean":"if [ -d ./dist ]; then find ./dist -maxdepth 1 -exec rm -rf {} +; fi","lint:fix":"eslint ./src --fix","prepublishOnly":"npm run build && npm run test"},"_npmUser":{"name":"hbarcelos","email":"rick.hjpbarcelos@gmail.com"},"_npmVersion":"3.10.10","description":"[![Standard - JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)","directories":{},"_nodeVersion":"6.12.1","dependencies":{"babel-runtime":"^6.26.0","source-map-support":"^0.5.0","continuation-local-storage":"^3.2.1"},"publishConfig":{"access":"public"},"devDependencies":{"chai":"^3.5.0","mocha":"^3.2.0","eslint":"^4.12.1","istanbul":"^0.4.5","babel-cli":"^6.26.0","babel-preset-env":"^1.6.1","eslint-plugin-node":"^5.2.1","eslint-plugin-import":"^2.8.0","babel-plugin-istanbul":"^4.1.5","eslint-plugin-promise":"^3.6.0","eslint-config-standard":"^10.2.1","eslint-plugin-standard":"^3.0.1","babel-plugin-transform-runtime":"^6.23.0"},"peerDependencies":{"pino":"^4.10.2","pino-noir":"^2.0.0"},"_npmOperationalInternal":{"tmp":"tmp/logger-1.0.7.tgz_1512683607813_0.9610774731263518","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"@revmob/logger","version":"1.1.0","author":{"name":"Henrique Barcelos","email":"henrique.barcelos@revmob.com"},"license":"ISC","_id":"@revmob/logger@1.1.0","maintainers":[{"name":"guisouza","email":"gui_souza@me.com"},{"name":"hbarcelos","email":"rick.hjpbarcelos@gmail.com"},{"name":"revmobadmin","email":"revmobads@revmob.com"}],"dist":{"shasum":"32f1538e99432426ecd3894c8282b1c37d775fd4","tarball":"https://registry.npmjs.org/@revmob/logger/-/logger-1.1.0.tgz","integrity":"sha512-i9CPY3lHbcl6pn/dI0I4lRYFPYOQ1eiaegsLYYD8ySWPIa8TR6Ua1ZkntJMMNYnl+U8I02Ny5rQPoYGxRJVkhw==","signatures":[{"sig":"MEUCIQD3wyxtXiujHGa8EgJTbwkf1BRgP6dgWUd2pmkFIcXmKQIgLXQs469babPGd9z3p68a+WS3jspfAR7erhhdIIuItbk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"dist/index.js","_from":".","module":"src/index.js","_shasum":"32f1538e99432426ecd3894c8282b1c37d775fd4","gitHead":"47cd5984222ff2f7299567dc04f59b34072eac97","scripts":{"lint":"eslint ./src","test":"tape -r babel-register test/**/*.test.js","build":"babel src/ -d dist/","clean":"if [ -d ./dist ]; then find ./dist -maxdepth 1 -exec rm -rf {} +; fi","lint:fix":"eslint ./src --fix","test:watch":"tape-watch -r babel-register test/**/*.test.js | tap-spec","prepublishOnly":"npm run build && npm run test"},"_npmUser":{"name":"hbarcelos","email":"rick.hjpbarcelos@gmail.com"},"_npmVersion":"3.10.10","description":"[![Standard - JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)","directories":{},"_nodeVersion":"6.12.2","dependencies":{"serializerr":"^1.0.3","babel-runtime":"^6.26.0","source-map-support":"^0.5.0","continuation-local-storage":"^3.2.1"},"publishConfig":{"access":"public"},"devDependencies":{"tape":"^4.8.0","eslint":"^4.12.1","istanbul":"^0.4.5","tap-spec":"^4.1.1","babel-cli":"^6.26.0","tape-watch":"^2.3.0","tap-prettify":"0.0.2","test-console":"^1.1.0","babel-register":"^6.26.0","babel-preset-env":"^1.6.1","eslint-plugin-node":"^5.2.1","eslint-plugin-import":"^2.8.0","babel-plugin-istanbul":"^4.1.5","eslint-plugin-promise":"^3.6.0","eslint-config-standard":"^10.2.1","eslint-plugin-standard":"^3.0.1","babel-plugin-transform-runtime":"^6.23.0","babel-plugin-syntax-object-rest-spread":"^6.13.0"},"peerDependencies":{"pino":"^4.10.2","pino-noir":"^2.0.0"},"_npmOperationalInternal":{"tmp":"tmp/logger-1.1.0.tgz_1513280625099_0.6113692165818065","host":"s3://npm-registry-packages"}}},"time":{"created":"2017-12-06T22:21:14.445Z","modified":"2026-03-06T15:30:39.794Z","1.0.0":"2017-12-06T22:21:14.445Z","1.0.1":"2017-12-06T22:27:04.364Z","1.0.2":"2017-12-07T19:58:34.393Z","1.0.3":"2017-12-07T20:41:23.024Z","1.0.4":"2017-12-07T20:55:30.704Z","1.0.5":"2017-12-07T21:02:57.115Z","1.0.7":"2017-12-07T21:53:29.001Z","1.1.0":"2017-12-14T19:43:46.272Z"},"author":{"name":"Henrique Barcelos","email":"henrique.barcelos@revmob.com"},"license":"ISC","description":"[![Standard - JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)","maintainers":[{"email":"rafael@artnic.io","name":"artnic"},{"email":"lucas.souza@infleux.co","name":"inf.simstm"},{"email":"igor.correa@infleux.co","name":"igor.correa"}],"readme":"# Logger\n\n[![Standard - JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\n[![Build Status](https://travis-ci.com/revmobgithub/logger.svg?token=v6zNMz91mpqSx5Z7QMt4&branch=master)](https://travis-ci.com/revmobgithub/logger)\n\nA Techmob InnerSource library for logging. It encapsulates the [`pino`](https://github.com/pinojs/pino) library, adding the following features:\n\n* Support for [`continuation-local-storage`](https://github.com/othiym23/node-continuation-local-storage) to allow distributed logging.\n* Sane default configurations.\n\nThere is no support for custom transports, as this should not be a responsibility of the application.\n\n## Principles\n\n### 1. Structured logging\n\nThe log format output is `JSON`.\n\n### 2. Context-first\n\nInstead of:\n\n```javascript\nlogger.info('Some message', context)\n```\n\nUse as:\n\n```javascript\nlogger.info(context, 'Some message')\n```\n\n### 3. Distributed logging ready\n\nExample: generating a unique ID for a request &mdash; if it's not provided through the `X-Request-ID` header &mdash; and attaching it to the log context:\n\nFor each incomming request, the generated `request-id` is guaranteed to be unique by the `uuid` implementation. An alternative to `uuid` is [`cuid`](https://github.com/ericelliott/cuid).\n\n```javascript\nconst uuid = require('uuid')\nconst express = require('express')\nconst logger = require('@revmob/logger').default()\n\nconst app = express()\n\napp.use([\n    (req, res, next) => {\n        logger.ns.run(() => {\n            const requestId = req.get('X-Request-ID') || uuid.v1()\n            logger.ns.set('request-id', requestId)\n            next()\n        }) \n    }\n])\n\nlogger.log('This is awesome!') \n```\n\nOutputs:\n```\n{ ... \"request-id\": \"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\", \"msg\": \"This is awesome!\", ...  }\n```\n\nThe `ns` property holds an instance of a [`continuation-local-storage`](https://github.com/othiym23/node-continuation-local-storage) *namespace*. See the docs for more details.\n\n## Installation\n\n```bash\nnpm install --save pino pino-noir @revmob/logger\n```\n\nBoth `pino` and `pino-noir` are *peer dependencies* of `@revmob/logger`.\n\n## Usage\n\n### General usage\n\nFor most use cases, you want to have just one instance of the logger in your application:\n\n```javascript\n// logger.js\nconst config = {\n   // ...\n}\n\nconst instance = require('@revmob/logger').default(config)\n\n// or\nimport logger from '@revmob/logger'\nconst instance = logger(config)\n```\n\nWhere `config` is an object containing configuration parameters accepted by [`pino`](https://github.com/pinojs/pino). It can also be ommited, \n\nExample:\n```javascript\nconst log = require('@revmob/logger').default()\n\nlog.trace('This entry will be shown')\nlog.debug('All entries with level above verbose will be shown')\nlog.info('I am shown')\nlog.warn('I am bigger than info')\nlog.error('Behold, I am the greatest!')\nlog.fatal('Poor child, I am the ultimate log!')\n```\n\nOutput:\n\n```json\n{\"level\":10,\"time\":1512596602556,\"msg\":\"This entry will be shown\",\"name\":\"main\",\"pid\":18886,\"hostname\":\"henrique-All-Series\",\"v\":1}\n{\"level\":20,\"time\":1512596602557,\"msg\":\"All entries with level above verbose will be shown\",\"name\":\"main\",\"pid\":18886,\"hostname\":\"henrique-All-Series\",\"v\":1}\n{\"level\":30,\"time\":1512596602558,\"msg\":\"I am shown\",\"name\":\"main\",\"pid\":18886,\"hostname\":\"henrique-All-Series\",\"v\":1}\n{\"level\":40,\"time\":1512596602558,\"msg\":\"I am bigger than info\",\"name\":\"main\",\"pid\":18886,\"hostname\":\"henrique-All-Series\",\"v\":1}\n{\"level\":50,\"time\":1512596602558,\"msg\":\"Behold, I am the greatest!\",\"name\":\"main\",\"pid\":18886,\"hostname\":\"henrique-All-Series\",\"v\":1}\n{\"level\":60,\"time\":1512596602558,\"msg\":\"Poor child, I am the ultimate log!\",\"name\":\"main\",\"pid\":18886,\"hostname\":\"henrique-All-Series\",\"v\":1}\n```\n\nIf we specify a `level` in the `config`, all logs bellow that threshold will not be displayed:\n\n```javascript\nconst log = require('@revmob/logger').default({\n    level: 'warn'\n})\n```\n\nOutput:\n\n```json\n{\"level\":40,\"time\":1512596602558,\"msg\":\"I am bigger than info\",\"name\":\"main\",\"pid\":18886,\"hostname\":\"henrique-All-Series\",\"v\":1}\n{\"level\":50,\"time\":1512596602558,\"msg\":\"Behold, I am the greatest!\",\"name\":\"main\",\"pid\":18886,\"hostname\":\"henrique-All-Series\",\"v\":1}\n{\"level\":60,\"time\":1512596602558,\"msg\":\"Poor child, I am the ultimate log!\",\"name\":\"main\",\"pid\":18886,\"hostname\":\"henrique-All-Series\",\"v\":1}\n```\n\n### Development time\n\nJSON logs are not exactly friendly to human eyes. To aid this, use `pino` CLI in development to get a better output:\n\n```javascript\nconst log = require('@revmob/logger').default()\n\nlog.trace('This entry will be shown')\nlog.debug('All entries with level above verbose will be shown')\nlog.info('I am shown')\nlog.warn('I am bigger than info')\nlog.error('Behold, I am the greatest!')\nlog.fatal('Poor child, I am the ultimate log!')\n\nlog.info({ foo: 'bar' }, 'Hey, look! I have context')\nlog.info(new Error('I\\'m an error'), 'Hey, look! I have an error context')\n```\n\nRunning:\n\n```bash\nnode app.js | npx pino pretty\n```\n\nOutput:\n\n![Pretty Print](http://pix.toile-libre.org/upload/original/1512597825.png)\n\n**NOTICE:** for `npm@<5.2.0`, `npx` is not available. Change the command after the pipe to `$(npm bin)/pino pretty`.\n\n### Forking\n\nWe can fork the logger to change some of its properties when needed:\n\n```javascript\nconst log = require('@revmob/logger').default()\n\nlog.trace('This entry will be shown')\nlog.debug('All entries with level above verbose will be shown')\nlog.info('I am shown')\nlog.warn('I am bigger than info')\nlog.error('Behold, I am the greatest!')\nlog.fatal('Poor child, I am the ultimate log!')\n\nlog.info({ foo: 'bar' }, 'Hey, look! I have context')\nlog.info(new Error('I\\'m an error'), 'Hey, look! I have an error context')\n\nconst child = log.child({\n  name: 'child',\n  level: 'error'\n})\n\nchild.trace('This entry will be shown')\nchild.debug('All entries with level above verbose will be shown')\nchild.info('I am shown')\nchild.warn('I am bigger than info')\nconsole.log('\\n\\n-----------------------------------------------\\n\\n')\nchild.error('Behold, I am the greatest!')\nchild.fatal('Poor child, I am the ultimate log!')\n```\n\nOutput:\n\n![Forking](http://pix.toile-libre.org/upload/original/1512598352.png)\n\n## Configuration\n\nThe `config` object is forwarded to [`pino`](https://github.com/pinojs/pino).\n\nThe default config is:\n\n```javascript\n({\n  level,\n  extreme,\n  base: {\n    name: 'main',\n    pid: process.pid,\n    hostname: hostname()\n  },\n  serializers: Object.assign(\n    {\n      req: req => ({\n        id: req.id,\n        method: req.method,\n        url: req.url,\n        body: req.body,\n        headers: req.headers,\n        remoteAddress: req.connection && req.connection.remoteAddress,\n        remotePort: req.connection && req.connection.remotePort\n      }),\n      res: pino.stdSerializers.res,\n      err: pino.stdSerializers.err\n    },\n    noir([\n      'err.options.auth.*',\n      'options.auth.*',\n      'auth.*',\n      'secret',\n      'password',\n      'pass'\n    ], '****')\n  )\n})\n```\n\nWe are free to patch this configuration.\n\n## Contributing to Logger\n\nContributions are always welcome, no matter how large or small. \nSee [Contributing](CONTRIBUTING.md).\n","readmeFilename":"README.md"}