{"_id":"@eggjs/logrotator@5.1.0","bugs":{"url":"https://github.com/eggjs/egg/issues"},"dist":{"shasum":"d9956c0e37bf7572649cca814951131a51b63257","tarball":"http://registry-npm.ywwl.com/@eggjs/logrotator/download/@eggjs/logrotator-5.1.0.tgz","fileCount":38,"integrity":"sha512-g861CC/xjvwjhiONQV9vDvITmyy+84mGSIju6Cou83ZH8jPkHFr9+RZezTfn96aNIj6IeMqrlieqaVjjuFyJQA==","signatures":[{"sig":"MEUCIQDyw0qd3j9hOzNNHRgFnawDtJb56WohxBvATDu+ol62lQIgBhPFesSJN28NKyUdFRmFskN7PPfIkiISLPggEja6GK0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIGyOU3marfPJSJlPANKQhRTzCRShuyVF3UmISubLrEi7AiAai6zWBqrt08l9Ddkvv7MPXgCVh2aENM5pQORP0f1UVw=="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2flogrotator@5.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":30281,"size":8817,"noattachment":false,"key":"/@eggjs/logrotator/-/@eggjs/logrotator-5.1.0.tgz"},"name":"@eggjs/logrotator","type":"module","types":"./dist/index.d.ts","author":{"name":"tianyi.jiangty"},"engines":{"node":">= 22.18.0"},"exports":{".":"./dist/index.js","./app":"./dist/app.js","./boot":"./dist/boot.js","./agent":"./dist/agent.js","./types":"./dist/types.js","./lib/utils":"./dist/lib/utils.js","./lib/rotator":"./dist/lib/rotator.js","./package.json":"./package.json","./lib/day_rotator":"./dist/lib/day_rotator.js","./app/extend/agent":"./dist/app/extend/agent.js","./lib/hour_rotator":"./dist/lib/hour_rotator.js","./lib/size_rotator":"./dist/lib/size_rotator.js","./config/config.default":"./dist/config/config.default.js","./app/extend/application":"./dist/app/extend/application.js","./app/schedule/clean_log":"./dist/app/schedule/clean_log.js","./app/schedule/rotate_by_file":"./dist/app/schedule/rotate_by_file.js","./app/schedule/rotate_by_hour":"./dist/app/schedule/rotate_by_hour.js","./app/schedule/rotate_by_size":"./dist/app/schedule/rotate_by_size.js"},"gitHead":"e9cc326c1a1b6f2d953162747e37dd3a7a7088dc","license":"MIT","scripts":{"typecheck":"tsc --noEmit"},"version":"5.1.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"aeb0c593-0933-4ad8-8c76-c71f073ed64d"}},"homepage":"https://github.com/eggjs/egg/tree/next/plugins/logrotator#readme","keywords":["egg","egg-plugin","eggPlugin","logger","logrotator"],"repository":{"url":"git+https://github.com/eggjs/egg.git","type":"git","directory":"plugins/logrotator"},"_npmVersion":"11.19.0","description":"logrotator for egg","directories":{},"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":"hyj1991","email":"yeekwanvong@gmail.com"},{"name":"killagu","email":"killa07071201@gmail.com"},{"name":"coolme200","email":"2001-wms@163.com"},{"name":"akitasummer","email":"644171127@qq.com"},{"name":"elrrrrrrr","email":"elrrrrrrr@gmail.com"},{"name":"niania","email":"ljracm@gmail.com"}],"_nodeVersion":"24.21.0","dependencies":{"moment":"^2.30.1","utility":"^2.5.0"},"publishConfig":{"access":"public","exports":{".":"./dist/index.js","./app":"./dist/app.js","./boot":"./dist/boot.js","./agent":"./dist/agent.js","./types":"./dist/types.js","./lib/utils":"./dist/lib/utils.js","./lib/rotator":"./dist/lib/rotator.js","./package.json":"./package.json","./lib/day_rotator":"./dist/lib/day_rotator.js","./app/extend/agent":"./dist/app/extend/agent.js","./lib/hour_rotator":"./dist/lib/hour_rotator.js","./lib/size_rotator":"./dist/lib/size_rotator.js","./config/config.default":"./dist/config/config.default.js","./app/extend/application":"./dist/app/extend/application.js","./app/schedule/clean_log":"./dist/app/schedule/clean_log.js","./app/schedule/rotate_by_file":"./dist/app/schedule/rotate_by_file.js","./app/schedule/rotate_by_hour":"./dist/app/schedule/rotate_by_hour.js","./app/schedule/rotate_by_size":"./dist/app/schedule/rotate_by_size.js"}},"_hasShrinkwrap":false,"devDependencies":{"egg":"4.2.0","glob":"^11.0.0","egg-logger":"^3.5.0","typescript":"^7.0.2","@eggjs/mock":"7.1.0","@types/node":"^24.10.2","@eggjs/schedule":"6.1.0"},"peerDependencies":{"egg":"4.2.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/logrotator_5.1.0_1791361640215_0.3353575369461397"},"readme":"# @eggjs/logrotator\n\n[![NPM version][npm-image]][npm-url]\n[![npm download][download-image]][download-url]\n[![Node.js Version](https://img.shields.io/node/v/@eggjs/logrotator.svg?style=flat)](https://nodejs.org/en/download/)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)\n![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/eggjs/security)\n\n[npm-image]: https://img.shields.io/npm/v/@eggjs/logrotator.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/@eggjs/logrotator\n[download-image]: https://img.shields.io/npm/dm/@eggjs/logrotator.svg?style=flat-square\n[download-url]: https://npmjs.org/package/@eggjs/logrotator\n\negg 的日志切割插件，默认会按照时间切割所有的 app.loggers。\n\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](LICENSE)\n\n## Contributors\n\n[![Contributors](https://contrib.rocks/image?repo=eggjs/egg)](https://github.com/eggjs/egg/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n","publish_time":1791361640314,"_cnpm_publish_time":1791361640314,"dist-tags":{"beta":"5.0.2-beta.27","latest":"5.1.0","rc":"5.0.2-rc.1"}}