{"id":13487451,"url":"https://github.com/eggjs/logrotator","last_synced_at":"2025-10-28T15:58:14.077Z","repository":{"id":45408771,"uuid":"63205576","full_name":"eggjs/logrotator","owner":"eggjs","description":"Log rotate plugin for egg","archived":false,"fork":false,"pushed_at":"2025-03-30T11:29:50.000Z","size":158,"stargazers_count":56,"open_issues_count":1,"forks_count":14,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-10-22T05:55:11.840Z","etag":null,"topics":["egg-logrotator","egg-plugin"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eggjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-07-13T01:55:30.000Z","updated_at":"2025-03-30T11:29:52.000Z","dependencies_parsed_at":"2024-11-09T19:29:20.016Z","dependency_job_id":"e9a49aca-d795-4435-b31e-6f9a1b8bb767","html_url":"https://github.com/eggjs/logrotator","commit_stats":{"total_commits":50,"total_committers":12,"mean_commits":4.166666666666667,"dds":0.6799999999999999,"last_synced_commit":"50cc53ad728f93d731833f32e49499606d04a390"},"previous_names":["eggjs/egg-logrotater","eggjs/logrotator"],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/eggjs/logrotator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Flogrotator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Flogrotator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Flogrotator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Flogrotator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eggjs","download_url":"https://codeload.github.com/eggjs/logrotator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Flogrotator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281467277,"owners_count":26506462,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-28T02:00:06.022Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["egg-logrotator","egg-plugin"],"created_at":"2024-07-31T18:00:59.529Z","updated_at":"2025-10-28T15:58:14.071Z","avatar_url":"https://github.com/eggjs.png","language":"TypeScript","readme":"# @eggjs/logrotator\n\n[![NPM version][npm-image]][npm-url]\n[![CI](https://github.com/eggjs/logrotator/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/logrotator/actions/workflows/nodejs.yml)\n[![Test coverage](https://img.shields.io/codecov/c/github/eggjs/logrotator.svg?style=flat-square)](https://codecov.io/gh/eggjs/logrotator)\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\nLogRotator for egg. Rotate all file of `app.loggers` by default\n\n## Install\n\n```bash\nnpm i @eggjs/logrotator\n```\n\n## Usage\n\n- `plugin.js`\n\n```js\nexports.logrotator = {\n  enable: true,\n  package: '@eggjs/logrotator',\n};\n```\n\n- `config.default.js`\n\n```js\n// if any files need rotate by file size, config here\nexports.logrotator = {\n  filesRotateByHour: [], // list of files that will be rotated by hour\n  hourDelimiter: '-', // rotate the file by hour use specified delimiter\n  filesRotateBySize: [], // list of files that will be rotated by size\n  maxFileSize: 50 * 1024 * 1024, // Max file size to judge if any file need rotate\n  maxFiles: 10, // pieces rotate by size\n  rotateDuration: 60000, // time interval to judge if any file need rotate\n  maxDays: 31, // keep max days log files, default is `31`. Set `0` to keep all logs\n  gzip: false, // use gzip compress logger on rotate file, default is `false`. Set `true` to enable\n};\n```\n\n## Feature\n\nBy default, LogRotator will rotate all files of `app.loggers` at 00:00 everyday, the format is `.log.YYYY-MM-DD` (`egg-web.log.2016-09-30`).\n\n### By Size\n\nRotate by size with config `filesRotateBySize`. when the file size is greater than `maxFileSize`, it will rename to `.log.1`.\n\nIf the file you renamed to is exists, it will increment by 1 (`.log.1` -\u003e `.log.2`), until `maxFiles`. if it reaches the `maxFiles`, then overwrite `.log.${maxFiles}`.\n\nFiles in `filesRotateBySize` won't be rotated by day.\n\nIf `file` is relative path, then will normalize to `path.join(this.app.config.logger.dir, file)`.\n\n### By Hour\n\nRotate by hour with config `filesRotateByHour`. rotate the file at 00 every hour, the format is `.log.YYYY-MM-DD-HH`.\n\nFiles in `filesRotateByHour` won't be rotated by day.\n\nIf `file` is relative path, then will normalize to `path.join(this.app.config.logger.dir, file)`.\n\n## Customize\n\nYou can use `app.LogRotator` to customize.\n\n```js\n// app/schedule/custom.js\nmodule.exports = app =\u003e {\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    async task() {\n      await 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 ksrcPath to targetPath\n    async 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\nDefine a method called `getRotateFiles`, return a map contains a pair of srcPath and targetPath.\n\n## Questions \u0026 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/logrotator)](https://github.com/eggjs/logrotator/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n","funding_links":[],"categories":["仓库"],"sub_categories":["[内置插件](https://eggjs.org/zh-cn/basics/plugin.html#%E6%8F%92%E4%BB%B6%E5%88%97%E8%A1%A8)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Flogrotator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feggjs%2Flogrotator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Flogrotator/lists"}