{"name":"@eggjs/logrotator","version":"4.1.0","keywords":["egg","eggPlugin","egg-plugin","logger","logrotator"],"author":{"name":"tianyi.jiangty"},"license":"MIT","_id":"@eggjs/logrotator@4.1.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"}],"homepage":"https://github.com/eggjs/logrotator#readme","bugs":{"url":"https://github.com/eggjs/egg/issues"},"dist":{"shasum":"cf8564aa6c2f7420c4d7e8189c8cc8dd9bd4554f","tarball":"http://registry-npm.ywwl.com/@eggjs/logrotator/download/@eggjs/logrotator-4.1.0.tgz","fileCount":93,"integrity":"sha512-WqvNbslzW99it4aGLuJYsfJdC/t7hWJSE4hvfgp0FVCZ22HyMPehojG04RGFfsxkik2P56MmAUZ/UUfB29z/Hg==","signatures":[{"sig":"MEUCIQCTlxbFAQAXPddjUBdkR5OEf1WuYoD+U1KCaIZJKn102AIgFimamMjEdPKzWTN65KxXOvuQ4604UpAvJKJDUj8+A8E=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@eggjs%2flogrotator@4.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":119132,"size":24941,"noattachment":false,"key":"/@eggjs/logrotator/-/@eggjs/logrotator-4.1.0.tgz"},"main":"./dist/commonjs/index.js","tshy":{"exports":{".":"./src/index.ts","./package.json":"./package.json"}},"type":"module","types":"./dist/commonjs/index.d.ts","module":"./dist/esm/index.js","engines":{"node":">= 18.19.0"},"exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./package.json":"./package.json"},"gitHead":"ba0231c38c4947d5cd51edf14c3537ab34c45f4a","scripts":{"ci":"egg-bin cov","lint":"oxlint","test":"egg-bin test","clean":"rimraf dist","preci":"npm run clean &&  npm run lint","postci":"npm run prepublishOnly && npm run clean","prepare":"husky","pretest":"npm run clean && npm run lint -- --fix","prepublishOnly":"tshy && tshy-after && attw --pack","test:snapshot:update":"SNAPSHOT_UPDATE=1 egg-bin test"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"eggPlugin":{"name":"logrotator","exports":{"import":"./dist/esm","require":"./dist/commonjs","typescript":"./src"},"dependencies":["schedule"]},"repository":{"url":"git+https://github.com/eggjs/logrotator.git","type":"git"},"_npmVersion":"10.8.2","description":"logrotator for egg","directories":{},"lint-staged":{"*":"prettier --write --ignore-unknown --cache","*.{ts,js,json,md,yml}":["prettier --ignore-unknown --write","oxlint --fix"]},"_nodeVersion":"20.19.0","dependencies":{"moment":"^2.30.1","utility":"^2.5.0","@eggjs/core":"^6.2.13"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"egg":"^4.0.5","glob":"^11.0.1","tshy":"3","husky":"9","oxlint":"^0.16.2","rimraf":"6","prettier":"3","supertest":"^6.3.3","@eggjs/bin":"7","egg-logger":"^3.6.1","tshy-after":"1","typescript":"5","@eggjs/mock":"^6.0.6","@types/node":"22","lint-staged":"15","@types/mocha":"10","snap-shot-it":"^7.9.10","@eggjs/tsconfig":"1","@arethetypeswrong/cli":"^0.17.4"},"_npmOperationalInternal":{"tmp":"tmp/logrotator_4.1.0_1743334198733_0.6328128869396805","host":"s3://npm-registry-packages-npm-production"},"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":1743334198951,"_cnpm_publish_time":1743334198951,"dist-tags":{"beta":"5.0.2-beta.27","latest":"5.1.0","rc":"5.0.2-rc.1"}}