{"name":"egg-logger","version":"3.6.0","author":{"url":"https://github.com/fengmk2","name":"fengmk2","email":"fengmk2@gmail.com"},"license":"MIT","_id":"egg-logger@3.6.0","maintainers":[{"name":"gxkl","email":"gxkl203@gmail.com"},{"name":"eggjs-admin","email":"fengmk2+eggjs@gmail.com"},{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"atian25","email":"atian25@qq.com"},{"name":"dead_horse","email":"dead_horse@qq.com"},{"name":"wanghx","email":"whxaxes@gmail.com"},{"name":"hyj1991","email":"yeekwanvong@gmail.com"},{"name":"killagu","email":"killa07071201@gmail.com"},{"name":"coolme200","email":"2001-wms@163.com"},{"name":"mansonchor.zzw","email":"mansonchor1987@gmail.com"},{"name":"hubcarl","email":"hubcarl@126.com"},{"name":"gemwuu","email":"gemwuu@gmail.com"},{"name":"akitasummer","email":"644171127@qq.com"},{"name":"popomore","email":"sakura9515@gmail.com"}],"homepage":"https://github.com/eggjs/egg-logger","bugs":{"url":"https://github.com/eggjs/egg-logger/issues"},"dist":{"shasum":"012c47facecc058a896a048501b45a0696a24842","tarball":"http://registry-npm.ywwl.com/egg-logger/download/egg-logger-3.6.0.tgz","fileCount":19,"integrity":"sha512-YEaPVTW6BDllNHqkdMOINgP//9bMrUvSt8GxPfFs26JXGSvLXdzt50k2cJcG24G9BQyzK4euAAuewB4SwCPISA==","signatures":[{"sig":"MEYCIQC/RcQDmlnJHLSbYeetOGbgTLhBlkgi1R11oKOva48ktQIhALk2OxHWdlVwdomfhKw66HL7H8YnmsZBXE+xhDdGY9rv","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/egg-logger@3.6.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":50991,"size":13238,"noattachment":false,"key":"/egg-logger/-/egg-logger-3.6.0.tgz"},"main":"index.js","types":"index.d.ts","engines":{"node":">=14.17.0"},"gitHead":"a52181ff63c7e0d7417359c49366be5d83c9c0dd","scripts":{"ci":"npm run lint && npm run cov","cov":"egg-bin cov --ts false","tsd":"tsd","lint":"eslint .","test":"npm run lint -- --fix && npm run test-local","test-local":"egg-bin test --ts false","contributor":"git-contributor"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"repository":{"url":"git+https://github.com/eggjs/egg-logger.git","type":"git"},"_npmVersion":"10.8.2","description":"egg logger","directories":{},"_nodeVersion":"18.20.5","dependencies":{"depd":"^2.0.0","chalk":"^4.1.2","utility":"^2.1.0","egg-errors":"^2.3.1","iconv-lite":"^0.6.3","circular-json-for-egg":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"mm":"^3.2.1","koa":"^2.14.1","tsd":"^0.28.1","coffee":"^5.5.0","eslint":"^8.29.0","egg-bin":"6","ts-node":"^10.9.1","benchmark":"^2.1.4","supertest":"^6.3.3","typescript":"5","@types/node":"^20.2.5","eslint-config-egg":"^12.1.0","beautify-benchmark":"^0.2.4"},"_npmOperationalInternal":{"tmp":"tmp/egg-logger_3.6.0_1732946903204_0.974831317422322","host":"s3://npm-registry-packages"},"readme":"# egg-logger\n\n[![NPM version][npm-image]][npm-url]\n[![CI](https://github.com/eggjs/egg-logger/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/egg-logger/actions/workflows/nodejs.yml)\n[![Test coverage][codecov-image]][codecov-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/egg-logger.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-logger\n[codecov-image]: https://codecov.io/github/eggjs/egg-logger/coverage.svg?branch=master\n[codecov-url]: https://codecov.io/github/eggjs/egg-logger?branch=master\n[snyk-image]: https://snyk.io/test/npm/egg-logger/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/egg-logger\n[download-image]: https://img.shields.io/npm/dm/egg-logger.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-logger\n\nEgg 的日志工具。\n\n![](diagram.png)\n\n主要由 Logger 和 Transport 两个基类组成。\n\nTransport 是一种写入日志的渠道，可以是终端、文件等等。\n\nLogger 是所有日志的基类，可以进行扩展。一个 Logger 可以添加多个 Transport，只要调用一次就可以将日志写入多个地方。\n\n---\n\n## Install\n\n```bash\n$ npm i egg-logger\n```\n\n## Usage\n\n创建一个 Logger，添加一个文件的 Transport\n\n```js\nconst Logger = require('egg-logger').Logger;\nconst FileTransport = require('egg-logger').FileTransport;\nconst ConsoleTransport = require('egg-logger').ConsoleTransport;\n\nconst logger = new Logger();\nlogger.set('file', new FileTransport({\n  file: '/path/to/file',\n  level: 'INFO',\n}));\nlogger.set('console', new ConsoleTransport({\n  level: 'DEBUG',\n}));\nlogger.debug('debug foo'); // 不会输出到文件，只输出到终端\nlogger.info('info foo');\nlogger.warn('warn foo');\nlogger.error(new Error('error foo'));\n```\n\n### 开启/关闭 Transport\n\n```js\nlogger.disable('file');\nlogger.info('info'); // 不会输出\nlogger.enable('file');\nlogger.info('info'); // 开启后会输出\n```\n\n### 汇集日志\n\n可以把日志复制一份到指定的日志对象，支持可选的 `options.excludes` 来排除对应的 tranport\n\n```js\nlogger.duplicate('error', errorLogger, { excludes: [ 'console' ] });\nlogger.error(new Error('print to errorLogger')); // 会多调用一次 `errorLogger.error`\n```\n\n### 重定向日志\n\n可以将日志重定向到指定的日志对象\n\n```js\noneLogger.redirect('debug', debugLogger); // oneLogger 的调试日志将被 debugLogger 接管，输出过去。\n```\n\n### 重新加载文件\n\n```js\nlogger.reload(); // will end the exists write stream and create a new one.\n```\n\n### 自定义 Transport\n\n可以自定义一个 Transport 用于输出日志，比如发送到服务器。\n\n```js\nconst urllib = require('urllib');\nconst Transport = require('egg-logger').Transport;\n\nclass UrllibTransport extends Transport {\n\n  log(level, args, meta) {\n    const msg = super.log(level, args, meta);\n    return urllib.request('url?msg=' + msg);\n  }\n}\n\nconst logger = new Logger();\nlogger.set('remote', new UrllibTransport({\n  level: 'DEBUG',\n}));\nlogger.info('info');\n```\n\n## console 默认打印级别设置\n\n设置环境变量 NODE_CONSOLE_LOGGRE_LEVEL = 'INFO' | 'WARN' | 'ERROR'\n\n## License\n\n[MIT](LICENSE)\n## Contributors\n\n[![Contributors](https://contrib.rocks/image?repo=eggjs/egg-logger)](https://github.com/eggjs/egg-logger/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n","publish_time":1732946903392,"_cnpm_publish_time":1732946903392,"dist-tags":{"latest":"3.6.1","latest-1":"1.8.0"}}