{"name":"@midwayjs/logger","version":"2.16.1","keywords":["midway","logger"],"license":"MIT","_id":"@midwayjs/logger@2.16.1","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"},{"name":"stone-jin","email":"1520006273@qq.com"}],"homepage":"https://github.com/midwayjs/logger#readme","bugs":{"url":"https://github.com/midwayjs/logger/issues"},"dist":{"shasum":"66bf4470bf6ec8d5fde9aabaca02fb8bfe5656ce","tarball":"http://registry-npm.ywwl.com/@midwayjs/logger/download/@midwayjs/logger-2.16.1.tgz","fileCount":32,"integrity":"sha512-hnPkz55gHxOzJQq8RxPCN4sth17K69dRLf5C6It7tH4HTq75rcEyYAdXV2g4xEOlLy31vHr6xHRysAFhAiinlg==","signatures":[{"sig":"MEYCIQDNe28XrUYjQ4Dmf72iT4qHdL6KAln3tUaJrrQq3kC+uQIhAPM7lhnFMkX+K4/3GAR5bzzORkupjJYaMzQoaGlaJKzV","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":101965,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiIG6BACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpEuBAAjFEJSsExB1hn/U4aQzKiVwM5JjbVtbqQpU8Lj6P1I7c1GPS7\r\n5nHmtXcfmwUIrGEy9/imdCxSwN9ekjNXefdnB0ObOb/4usVRHw26clUdHXe9\r\nFHsphmPtbjz5P8e96iZTjQ2wUnrzZTeCHtoC5fblFr1LiXb0NNOfiT2PIa3L\r\n1UNGxGX9M/Ez2Jke0QC9yfN+Gj/1bRkJTIbIwW5l7qFsmnK+xjCdPfsOtWNJ\r\ntPCdPSD8zKa1ny0WyYyowESndkQ17cYi/ok0Kiq0GQP6xbPMwkLhq22i//Zv\r\nOBlf3ngzvhnr/hIVd5UNeBgZihrHu8DU2XLUjdp+Y4kYavVTDyhkVCS+4ij8\r\nIeemkMtvwT74MrkU2shT7/A0CtfSWe5xoIO++c2uEcctL5BukNL5/01Mz/DE\r\nOXMzu5eQf5qTt70dJp9urA4WjUBk8E5UT1pwSDUPMkTyLL2G7vV4sUzcIlIK\r\n1H6peEkb99jgsCeciAMwOk2p8VjuS5GAwk45HCY9mHpie4+7gYTXNt/VlT7W\r\nnyeVtS+n3oUwz9U2z1P2rhyngnqQrZXBJJ16JLxd3Ooyqb/qBd925od6X8rJ\r\nGlPfTXYeN3ahOPZkjaIAkfXKKj+Y+cCurBKWlYGR/puAl0Jh/vYRp+1ag0NJ\r\nv9FvOiUYXwg9v6Ea4EJWJktvsvf2V487Qjw=\r\n=H06j\r\n-----END PGP SIGNATURE-----\r\n","size":23963,"noattachment":false,"key":"/@midwayjs/logger/-/@midwayjs/logger-2.16.1.tgz"},"main":"dist/index","engines":{"node":">=10"},"gitHead":"7b1ccd62637b71c4c9dec8a6fc837fb439cf0d8b","scripts":{"cov":"cross-env node --require=ts-node/register ./node_modules/.bin/jest --coverage --forceExit","lint":"mwts check","test":"cross-env node --require=ts-node/register ./node_modules/.bin/jest","build":"rm -rf dist && tsc","lint:fix":"mwts fix"},"typings":"dist/index.d.ts","_npmUser":{"name":"czy88840616","email":"czy88840616@gmail.com"},"repository":{"url":"git+ssh://git@github.com/midwayjs/logger.git","type":"git"},"_npmVersion":"7.10.0","description":"midway logger sdk","directories":{},"_nodeVersion":"16.0.0","dependencies":{"dayjs":"^1.10.7","winston":"^3.3.3","object-hash":"^3.0.0","triple-beam":"^1.3.0","winston-transport":"^4.4.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"27.5.1","mwts":"1.3.0","colors":"1.4.0","threads":"1.7.0","ts-jest":"27.1.3","ts-node":"10.6.0","fs-extra":"10.0.1","cross-env":"7.0.3","egg-logger":"2.7.1","typescript":"4.6.2","@types/jest":"27.4.1","@types/node":"16.11.26"},"_npmOperationalInternal":{"tmp":"tmp/logger_2.16.1_1646292609699_0.865734459901913","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":1646292609850,"_cnpm_publish_time":1646292609850,"dist-tags":{"alinode-stable":"3.0.0-alpha.42","alpha":"3.0.0-alpha.43","beta":"4.0.0","latest":"4.1.0"}}