{"name":"egg-logrotator","version":"3.2.0","keywords":["egg","eggPlugin","egg-plugin","logger","logrotator"],"author":{"name":"tianyi.jiangty"},"license":"MIT","_id":"egg-logrotator@3.2.0","maintainers":[{"name":"jtyjty99999","email":"jtyjty99999@126.com"},{"name":"atian25","email":"atian25@qq.com"},{"name":"dead_horse","email":"dead_horse@qq.com"},{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"popomore","email":"sakura9515@gmail.com"},{"name":"eggjs-admin","email":"fengmk2+eggjs@gmail.com"}],"homepage":"https://github.com/eggjs/egg-logrotator#readme","bugs":{"url":"https://github.com/eggjs/egg/issues"},"dist":{"shasum":"77eeeddc634367bea014d5044d5bfb6ad829bef8","tarball":"http://registry-npm.ywwl.com/egg-logrotator/download/egg-logrotator-3.2.0.tgz","fileCount":18,"integrity":"sha512-2KYN4wwBd15FYbNtLxL7IoIkFL7JuHHA3eXWZd5zVKfWgeoy4J+oTnCLDixW1UhVIdehL0q1oQxEldWm5af1Eg==","signatures":[{"sig":"MEUCIQCvvctSS12HOCGN2vtIK5ysw44x0cHdICbpeWxmloR40wIgA9pLLKTHAAwDk2crjvZNPVJ1pqA/LajKr6u4Py9xOjU=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/egg-logrotator@3.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":23648,"size":7066,"noattachment":false,"key":"/egg-logrotator/-/egg-logrotator-3.2.0.tgz"},"engines":{"node":">=8.0.0"},"gitHead":"0215cc5874ff02943ee942660d3019124430941f","scripts":{"ci":"npm run lint && npm run cov","cov":"egg-bin cov","lint":"eslint .","test":"npm run lint -- --fix && npm run test-local","test-local":"egg-bin test"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"eggPlugin":{"dep":["schedule"],"name":"logrotator"},"repository":{"url":"git+https://github.com/eggjs/egg-logrotator.git","type":"git"},"_npmVersion":"10.7.0","description":"logrotator for egg","directories":{},"_nodeVersion":"18.20.4","dependencies":{"mz":"^2.7.0","moment":"^2.24.0"},"_hasShrinkwrap":false,"devDependencies":{"egg":"^2.0.0","glob":"^7.1.3","eslint":"8","egg-bin":"^4.13.0","pedding":"1","egg-mock":"^3.22.2","egg-logger":"^2.4.1","mz-modules":"^2.1.0","eslint-config-egg":"12"},"_npmOperationalInternal":{"tmp":"tmp/egg-logrotator_3.2.0_1727510593779_0.0701105290907873","host":"s3://npm-registry-packages"},"readme":"# egg-logrotator\n\n[![NPM version][npm-image]][npm-url]\n[![CI](https://github.com/eggjs/egg-logrotator/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/egg-logrotator/actions/workflows/nodejs.yml)\n[![Test coverage](https://img.shields.io/codecov/c/github/eggjs/egg-logrotator.svg?style=flat-square)](https://codecov.io/gh/eggjs/egg-logrotator)\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/egg-logrotator.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-logrotator\n[download-image]: https://img.shields.io/npm/dm/egg-logrotator.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-logrotator\n\negg 的日志切割插件，默认会按照时间切割所有的 app.loggers。\n\n## 配置\n\n- `plugin.js`\n\n```js\nexports.logrotator = true;\n```\n\n- `config.default.js`\n\n```js\n// 如果有需要按照文件大小切割的日志，在这里配置\nexports.logrotator = {\n  filesRotateByHour: [],           // 需要按小时切割的文件\n  hourDelimiter: '-',              // 按照小时切割的文件, 小时部分的分隔符.\n  filesRotateBySize: [],           // 需要按大小切割的文件，其他日志文件仍按照通常方式切割\n  maxFileSize: 50 * 1024 * 1024,   // 最大文件大小，默认为50m\n  maxFiles: 10,                    // 按大小切割时，文件最大切割的份数\n  rotateDuration: 60000,           // 按大小切割时，文件扫描的间隔时间\n  maxDays: 31,                     // 日志保留最久天数\n};\n```\n\n## 功能说明\n\nlogrotator 默认在每日0点按照时间切割，会将 app.loggers 下所有的 logger 都进行切割，格式为 `.log.YYYY-MM-DD`，如 `egg-web.log.2016-09-30`。\n\n### 按大小切割\n\n可以配置 `filesRotateBySize` 文件列表按大小切割，当文件大于 `maxFileSize` 时进行切割，格式为 `.log.1`。\n\n当已有切割文件时会将原文件自增 1，如 `.log.1` -> `.log.2`。当切割分数大于 `maxFiles` 时会覆盖最后一份。\n\n配置了这个功能的文件不会再按默认切割。\n\n如配置为相对路径，则默认会转换为 `path.join(this.app.config.logger.dir, file)`。\n\n### 按小时切割\n\n可以配置 `filesRotateBySize` 文件列表按小时切割，每小时0分开始切割，格式为 `.log.YYYY-MM-DD-HH`。\n\n配置了这个功能的文件不会再按默认切割。\n\n如配置为相对路径，则默认会转换为 `path.join(this.app.config.logger.dir, file)`。\n\n## 自定义\n\n你可以使用 `app.LogRotator` 来自定义切割。\n\n```js\n// app/schedule/custom.js\nmodule.exports = app => {\n  const rotator = getRotator(app);\n  return {\n    // https://github.com/eggjs/egg-schedule\n    schedule: {\n      type: 'worker', // only one worker run this task\n      cron: '10 * * * *', // custom cron, or use interval\n    },\n    * task() {\n      yield rotator.rotate();\n    }\n  };\n};\n\nfunction getRotator(app) {\n  class CustomRotator extends app.LogRotator {\n    // return map that contains a pair of srcPath and targetPath\n    // LogRotator will rename srcPath to targetPath\n    // 返回一个 map，其中包含 srcPath 和 targetPath，\n    // LogRotator 会将 srcPath 重命名成 targetPath\n    * getRotateFiles() {\n      const files = new Map();\n      const srcPath = '/home/admin/foo.log';\n      const targetPath = '/home/admin/foo.log.2016.09.30';\n      files.set(srcPath, { srcPath, targetPath });\n      return files;\n    }\n  }\n  return new CustomRotator({ app });\n}\n```\n\n你只需要定义一个 getRotateFiles 方法，指定重命名的 map。\n\n## Questions & Suggestions\n\nPlease open an issue [here](https://github.com/eggjs/egg/issues).\n\n## License\n\n[MIT](https://github.com/eggjs/egg-logrotator/blob/master/LICENSE)\n\n## Contributors\n\n[![Contributors](https://contrib.rocks/image?repo=eggjs/egg-logrotator)](https://github.com/eggjs/egg-logrotator/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n","publish_time":1727510593954,"_cnpm_publish_time":1727510593954,"dist-tags":{"latest":"3.2.0","latest-2":"2.3.3","release-3.x":"3.2.0"}}