{"name":"@midwayjs/logger","version":"2.6.13","keywords":["midway","logger"],"license":"MIT","_id":"@midwayjs/logger@2.6.13","maintainers":[{"name":"czy88840616","email":"czy88840616@gmail.com"},{"name":"legendecas","email":"legendecas@gmail.com"},{"name":"echosoar","email":"82163514@qq.com"},{"name":"lellansin","email":"lellansin@gmail.com"},{"name":"lxxyx","email":"Lxxyxzj@gmail.com"}],"homepage":"https://github.com/midwayjs/midway#readme","bugs":{"url":"https://github.com/midwayjs/midway/issues"},"dist":{"shasum":"ea16bac615784b88a6a279d4d5c70411b3479a9f","tarball":"http://registry-npm.ywwl.com/@midwayjs/logger/download/@midwayjs/logger-2.6.13.tgz","fileCount":16,"integrity":"sha512-dr57FG9yVV5GDZGKjNR8LC0kky7bRqvprSsCb62EwbA8M9grNUlu8D+zDYs3+xoJB6d0cqlik8rkg9p5LmUrMQ==","signatures":[{"sig":"MEQCIBlY+sLFxFGWs+4gqrnqwHUe86oVgGi0U3tcVXFKUygaAiAU3bWdh0sgnH3NwnxYRpINqMqPtFiCsnafx/1Rt2YuIg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":24501,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgCRlmCRA9TVsSAnZWagAAtEkQAKUfFZTwbmFc+/NrJEar\nmpLDvQc1117KQ4tyxXNS/etWiSbs7Q0sfcy7lx2J7HWsEu+GihNkTezEYiQp\nZ8EYWDkch1y4jbIO0DYIn2Bws0tZWz6ZUIdnyrlXUygWzWqRurlcxmbRe+df\ngIp9ZBiIKgfRZzzlU3jzaO0JhSbFof3ujNaiidGChGR51B/20O7QW3+zQg71\nCaELw79AH8j6kzBGe7jHGhwF6X2BwQtCRSFp9HsutX8F/pIunMDS9k0LH8sT\n0mBtqRcAQwahS1coFdxklYIq5GCHZHG2qZg/4Hnb4HVGd3Hd+3oCeBGQb9xN\nK5XR/Q8MHQt99E/g0vbVfU8S2uovjdC/FX+JmVL40F5QOsbgUqz+6fokHZMg\nINdbq2RkVWLmrixYD0lrHOYoYeH9nbIi4m8DKcvntuW3zjhzfVs+DaajsrCc\nJUpqH47c8h2NZH65xVdnkOc+oQ56bUrSv2hABi4tLt+p6DFzCjRCI4UdzqXS\nTdICTNq64Ohrfk2Q3ubZrab1X67zguGOuDY9BS3/6clwmKg7QkXKG8DiXItk\nKMGuTqMo82or1QmPVrvlA3VN69/RYctu8/9QxfaHhnUqMbYvj6CfpaNbpjJd\nPboXyEsqyDW2rhsK7rgev3Aq/cbUQzVjSOjh3KakraZ3WnUoPZoiF8g9pmvn\nNc/A\r\n=MPni\r\n-----END PGP SIGNATURE-----\r\n","size":6950,"noattachment":false,"key":"/@midwayjs/logger/-/@midwayjs/logger-2.6.13.tgz"},"main":"dist/index","engines":{"node":">= 10"},"gitHead":"28acc7dd74a60d2ef9c6b39fe469b3fc2b9fa106","scripts":{"cov":"midway-bin cov --ts","test":"midway-bin test --ts","build":"midway-bin build -c"},"typings":"dist/index.d.ts","_npmUser":{"name":"czy88840616","email":"czy88840616@gmail.com"},"repository":{"url":"git+ssh://git@github.com/midwayjs/midway.git","type":"git"},"_npmVersion":"lerna/3.22.1/node@v14.5.0+x64 (darwin)","description":"[![Package Quality](http://npm.packagequality.com/shield/@midwayjs/logger.svg)](http://packagequality.com/#?package=@midwayjs/logger) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/midwayjs/midway/pulls)","directories":{},"_nodeVersion":"14.5.0","dependencies":{"winston":"^3.3.3","triple-beam":"^1.3.0","winston-transport":"^4.4.0","winston-daily-rotate-file":"^4.5.0"},"_hasShrinkwrap":false,"devDependencies":{"fs-extra":"^8.0.1","egg-logger":"^2.4.2","@midwayjs/cli":"^1.2.36"},"_npmOperationalInternal":{"tmp":"tmp/logger_2.6.13_1611209062098_0.0614860198062841","host":"s3://npm-registry-packages"},"readme":"# @midwayjs/logger\n\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/midwayjs/midway/pulls)\n\n@midwayjs/logger is a log module for midway project.\n\n## Install\n\n```bash\n$ npm install @midwayjs/logger --save\n```\n\n## Create Logger\n\n```ts\nimport { loggers } from '@midwayjs/logger';\n\nconst logger = loggers.createLogger('logger', {\n  // some logger options\n})\n```\n\n\n\n## Create With Transport\n\nCreate logger with console and file transports instance.\n\n```typescript\nimport { loggers, ConsoleTransport, FileTransport } from '@midwayjs/logger';\n\nconst logger = loggers.createLogger('logger', {\n  transports: {\n    console: new ConsoleTransport(),\n    file: new FileTransport({\n      dir: '...',\n      fileLogName: 'app.log',\n    }),\n  }\n})\n```\n\nCreate console logger.\n\n```typescript\nconst logger = loggers.createLogger('consoleLogger', {\n  transports: {\n    console: new ConsoleTransport(),\n  }\n})\n```\n\nCreate logger with options mode.\n\n```typescript\nconst logger = loggers.createLogger('consoleLogger', {\n  transports: {\n    console: {\n      autoColors: true,\n    },\n    file: {\n      dir: '...',\n      fileLogName: 'app.log',\n    }\n  }\n})\n```\n\n\n\n## Logger Output Method\n\n```ts\nlogger.debug('debug info');\nlogger.info('启动耗时 %d ms', Date.now() - start);\nlogger.warn('warning!');\nlogger.error(new Error('my error'));\nlogger.write('abcde');\n```\n\n\n\n## Logger Level\n\nlog level is divided into the following categories, and the log level decreases sequentially (the larger the number, the lower the level):\n\n```ts\nconst levels = {\n  none: 0,\n  error: 1,\n  trace: 2,\n  warn: 3,\n  info: 4,\n  verbose: 5,\n  debug: 6,\n  silly: 7,\n  all: 8,\n}\n```\n\nSet level for all transports\n\n```typescript\nconst logger = loggers.createLogger('logger', {\n  // ...\n  level: 'warn',\n});\n\n// not output\nlogger.debug('debug info');\n\n// not output\nlogger.info('debug info');\n```\n\n\n\n## Format and ContextFormat\n\nAdd logger format and context format.\n\n```typescript\nconst logger = loggers.createLogger('logger', {\n  // ...\n  format: info => {\n    return `${info.timestamp} ${info.message}`;\n  },\n  contextFormat: info => {\n    return `${info.timestamp} [${info.ctx.traceId}] ${info.message}`;\n  }\n});\n```\n\ninfo is a default metadata, include some properties.\n\n\n\n## Tranports\n\nThe actual behavior of the log output we call the transport.The log library has four built-in default Transports.\n\n* `ConsoleTransport` Output message to stdout and stderr with color.\n* `FileTransport` Output message to file and rotate by self.\n* `ErrorTransport` Inherit `FileTransport` and only output error message.\n* `JSONTransport` Inherit `FileTransport` and output json format.\n\nThe above Transports are all registered by default and can be configured by the name when registering.\n\n```typescript\nconst logger = loggers.createLogger('consoleLogger', {\n  transports: {\n    console: {/*...options*/},\n    file: {/*...options*/},\n    error: {/*...options*/},\n    json: {/*...options*/},\n  }\n});\n```\n\n\n\n## Implement a new Transport\n\nInherit Transport abstract class and implement `log` and `close` method.\n\n```typescript\nimport { Transport, ITransport } from '@midwayjs/logger';\n\nexport interface CustomTransportOptions {\n  // ...\n}\n\nexport class CustomTransport extends Transport<CustomTransportOptions> implements ITransport {\n  log(level: LoggerLevel | false, meta: LogMeta, ...args) {\n    // save file or post to remote server\n  }\n  \n  close() {}\n}\n```\n\nRegister class to `TransportManager` before used.\n\n```typescript\nimport { TransportManager } from '@midwayjs/logger';\n\nTransportManager.set('custom', CustomTransport);\n```\n\nAnd you can configure it in your code.\n\n```typescript\nconst logger = loggers.createLogger('consoleLogger', {\n  transports: {\n    custom: {/*...options*/}\n  }\n});\n```\n\n\n\n\n## Default Logger Options\n\nfind more options in [interface](https://github.com/midwayjs/logger/blob/main/src/interface.ts).\n\n\n## License\n\n[MIT]((http://github.com/midwayjs/logger/blob/master/LICENSE))\n","publish_time":1611209062229,"_cnpm_publish_time":1611209062229,"dist-tags":{"alinode-stable":"3.0.0-alpha.42","alpha":"3.0.0-alpha.43","beta":"4.0.0","latest":"4.1.0"}}