From b61d81dc209a3650e3ad66b75eabf866e831fb04 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Mon, 3 Feb 2025 18:40:56 +0800 Subject: [PATCH] fix: use @eggjs/logrotator --- .github/workflows/pr-contributor-welcome.yml | 34 -------------------- index-old.d.ts | 1 - package.json | 2 +- site/docs/basics/plugin.md | 2 +- site/docs/basics/plugin.zh-CN.md | 2 +- site/docs/core/logger.md | 4 +-- site/docs/core/logger.zh-CN.md | 5 +-- src/config/plugin.ts | 2 +- src/lib/types.ts | 2 ++ test/index.test-d.ts | 8 +++++ test/lib/plugins/logrotator.test.ts | 3 +- 11 files changed, 21 insertions(+), 44 deletions(-) delete mode 100644 .github/workflows/pr-contributor-welcome.yml diff --git a/.github/workflows/pr-contributor-welcome.yml b/.github/workflows/pr-contributor-welcome.yml deleted file mode 100644 index ce5382bee9..0000000000 --- a/.github/workflows/pr-contributor-welcome.yml +++ /dev/null @@ -1,34 +0,0 @@ -# 当 PR 被合并时,留言欢迎加入共建群 -name: PullRequest Contributor Welcome - -on: - pull_request_target: - types: - - closed - paths: - - 'app/**' - - 'site/**' - - 'config/**' - - 'lib/**' - - 'test/**' - - '*.js' - - '*.ts' - -jobs: - check-merged: - runs-on: ubuntu-latest - needs: read-file - if: github.event.pull_request.merged == true - steps: - - uses: actions-cool/maintain-one-comment@v3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - body: | - 🎉 Thanks for contribution. Please feel free to join DingTalk Social Community (Provide the PR link please). - - 🎉 感谢参与贡献,欢迎扫码(或搜索群号 21751340)加入钉钉社区(进群后请提供 PR 地址)。 - - - - - body-include: '' diff --git a/index-old.d.ts b/index-old.d.ts index b055d8874c..cfe28f351c 100644 --- a/index-old.d.ts +++ b/index-old.d.ts @@ -33,7 +33,6 @@ // } from 'egg-core'; // import EggCookies = require('egg-cookies'); // import 'egg-multipart'; -// import 'egg-logrotator'; // import 'egg-view'; // declare module 'egg' { diff --git a/package.json b/package.json index 6f08be1b14..972ac10985 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "@eggjs/development": "^4.0.0", "@eggjs/i18n": "^3.0.1", "@eggjs/jsonp": "^3.0.0", + "@eggjs/logrotator": "^4.0.0", "@eggjs/onerror": "^3.0.0", "@eggjs/schedule": "^5.0.2", "@eggjs/security": "^4.0.0", @@ -36,7 +37,6 @@ "cluster-client": "^3.7.0", "egg-errors": "^2.3.2", "egg-logger": "^3.6.1", - "egg-logrotator": "^3.2.0", "egg-multipart": "^3.5.0", "egg-view": "^2.1.4", "extend2": "^4.0.0", diff --git a/site/docs/basics/plugin.md b/site/docs/basics/plugin.md index 1b09fd093d..0bc414d0ea 100644 --- a/site/docs/basics/plugin.md +++ b/site/docs/basics/plugin.md @@ -167,7 +167,7 @@ Specific consolidation rules can be found in [Configuration](./config.md).   - [multipart](https://github.com/eggjs/egg-multipart) File Streaming Upload   - [security](https://github.com/eggjs/security) Security   - [development](https://github.com/eggjs/development) Development Environment Configuration -   - [logrotator](https://github.com/eggjs/egg-logrotator) Log segmentation +   - [logrotator](https://github.com/eggjs/logrotator) Log segmentation   - [schedule](https://github.com/eggjs/schedule) Timing tasks   - [static](https://github.com/eggjs/static) Static server   - [jsonp](https://github.com/eggjs/jsonp) jsonp support diff --git a/site/docs/basics/plugin.zh-CN.md b/site/docs/basics/plugin.zh-CN.md index 4075883383..f91922d10c 100644 --- a/site/docs/basics/plugin.zh-CN.md +++ b/site/docs/basics/plugin.zh-CN.md @@ -167,7 +167,7 @@ exports.mysql = { - [multipart](https://github.com/eggjs/egg-multipart) 文件流式上传 - [security](https://github.com/eggjs/security) 安全 - [development](https://github.com/eggjs/development) 开发环境配置 - - [logrotator](https://github.com/eggjs/egg-logrotator) 日志切分 + - [logrotator](https://github.com/eggjs/logrotator) 日志切分 - [schedule](https://github.com/eggjs/schedule) 定时任务 - [static](https://github.com/eggjs/static) 静态服务器 - [jsonp](https://github.com/eggjs/jsonp) jsonp 支持 diff --git a/site/docs/core/logger.md b/site/docs/core/logger.md index 492c3fba7e..3058f3d401 100644 --- a/site/docs/core/logger.md +++ b/site/docs/core/logger.md @@ -312,7 +312,7 @@ Performance is what we always consider as important part in our services so that ## Log Sharding -One common requirement you can find in enterprise logs is automatic log sharding, which offers a convenient way for management. Luckily, Egg takes [egg-logrotator](https://github.com/eggjs/egg-logrotator) as built-in solution to meet the need. +One common requirement you can find in enterprise logs is automatic log sharding, which offers a convenient way for management. Luckily, Egg takes [@eggjs/logrotator](https://github.com/eggjs/logrotator) as built-in solution to meet the need. ### Daily Sharding @@ -369,4 +369,4 @@ Generally, requests are frequent events to Web services, so writing logs into di > Logs will be firstly transferred into memory, and then Egg will asynchronously write them into files by second. -More about [egg-logger](https://github.com/eggjs/egg-logger) and [egg-logrotator](https://github.com/eggjs/egg-logrotator)。 +More about [egg-logger](https://github.com/eggjs/egg-logger) and [@eggjs/logrotator](https://github.com/eggjs/logrotator)。 diff --git a/site/docs/core/logger.zh-CN.md b/site/docs/core/logger.zh-CN.md index ecd68e4084..9b07cae2e1 100644 --- a/site/docs/core/logger.zh-CN.md +++ b/site/docs/core/logger.zh-CN.md @@ -306,9 +306,10 @@ app.getLogger('errorLogger').set('remote', new RemoteErrorTransport({ level: 'ER ``` 上述代码示例中,虽然比较简单,但是在实际使用时需要考虑性能问题。通常采取先暂存至内存,再定时上传的策略,以此优化性能。 + ## 日志切割 -企业级日志一个最常见的需求之一是对日志进行自动切割,以方便管理。框架对日志切割的支持由 [egg-logrotator](https://github.com/eggjs/egg-logrotator) 插件提供。 +企业级日志一个最常见的需求之一是对日志进行自动切割,以方便管理。框架对日志切割的支持由 [@eggjs/logrotator](https://github.com/eggjs/logrotator) 插件提供。 ### 按天切割 @@ -369,4 +370,4 @@ module.exports = (appInfo) => { > 日志同步写入内存,异步每隔一段时间(默认 1 秒)进行刷盘。 -更多细节,请参考 [egg-logger](https://github.com/eggjs/egg-logger) 和 [egg-logrotator](https://github.com/eggjs/egg-logrotator)。 +更多细节,请参考 [egg-logger](https://github.com/eggjs/egg-logger) 和 [@eggjs/logrotator](https://github.com/eggjs/logrotator)。 diff --git a/src/config/plugin.ts b/src/config/plugin.ts index 9c51dbc04c..094bca10b6 100644 --- a/src/config/plugin.ts +++ b/src/config/plugin.ts @@ -83,7 +83,7 @@ export default { */ logrotator: { enable: true, - package: 'egg-logrotator', + package: '@eggjs/logrotator', }, /** diff --git a/src/lib/types.ts b/src/lib/types.ts index db96f8f154..d560d1cd95 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -26,6 +26,8 @@ import '@eggjs/security'; import '@eggjs/schedule'; import '@eggjs/session'; import '@eggjs/onerror'; +import '@eggjs/logrotator'; + export type { EggAppInfo, } from '@eggjs/core'; diff --git a/test/index.test-d.ts b/test/index.test-d.ts index 10a337a3dd..6728743a53 100644 --- a/test/index.test-d.ts +++ b/test/index.test-d.ts @@ -1,5 +1,6 @@ import { expectType } from 'tsd'; import { EggCore, Context } from '@eggjs/core'; +import { LogRotator } from '@eggjs/logrotator'; import { Application, IBoot, ILifecycleBoot, LoggerLevel, @@ -17,6 +18,13 @@ expectType(app.messenger); expectType(app.messenger.broadcast('test')); expectType(app.loggers.reload()); +class MyLogRotator extends LogRotator { + async getRotateFiles() { + return new Map(); + } +} +expectType(new MyLogRotator({ app })); + const ctx = app.createAnonymousContext(); expectType>(app.runInAnonymousContextScope(async ctx => { diff --git a/test/lib/plugins/logrotator.test.ts b/test/lib/plugins/logrotator.test.ts index 3eae1d48d9..447de2b8db 100644 --- a/test/lib/plugins/logrotator.test.ts +++ b/test/lib/plugins/logrotator.test.ts @@ -14,11 +14,12 @@ describe('test/lib/plugins/logrotator.test.ts', () => { after(() => app.close()); it('should rotate log file default', async () => { - const file = importResolve('egg-logrotator/app/schedule/rotate_by_file.js'); + const file = importResolve('@eggjs/logrotator/dist/esm/app/schedule/rotate_by_file.js'); // console.log('job', file); await app.runSchedule(file); await scheduler.wait(1000); const files = (await fs.readdir(app.config.logger.dir)).filter(f => f.includes('.log.')); + console.log(files); assert(files.length > 0); files.forEach(file => { assert(/\.log\.\d{4}-\d{2}-\d{2}$/.test(file));