Skip to content

Commit 351a022

Browse files
authored
fix: use @eggjs/logrotator (#5390)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Chores** - Removed an automated contributor welcome workflow and updated the logging dependency. - **Documentation** - Refined documentation links and descriptions to reflect the updated logging system. - **Refactor** - Adjusted configuration settings for improved integration of the enhanced logging rotation. - **Tests** - Enhanced test coverage to validate the updated log rotation functionality. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent cb36fca commit 351a022

File tree

12 files changed

+33
-44
lines changed

12 files changed

+33
-44
lines changed

.github/workflows/pr-contributor-welcome.yml

-34
This file was deleted.

index-old.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
// } from 'egg-core';
3434
// import EggCookies = require('egg-cookies');
3535
// import 'egg-multipart';
36-
// import 'egg-logrotator';
3736
// import 'egg-view';
3837

3938
// declare module 'egg' {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@eggjs/development": "^4.0.0",
2626
"@eggjs/i18n": "^3.0.1",
2727
"@eggjs/jsonp": "^3.0.0",
28+
"@eggjs/logrotator": "^4.0.0",
2829
"@eggjs/onerror": "^3.0.0",
2930
"@eggjs/schedule": "^5.0.2",
3031
"@eggjs/security": "^4.0.0",
@@ -36,7 +37,6 @@
3637
"cluster-client": "^3.7.0",
3738
"egg-errors": "^2.3.2",
3839
"egg-logger": "^3.6.1",
39-
"egg-logrotator": "^3.2.0",
4040
"egg-multipart": "^3.5.0",
4141
"egg-view": "^2.1.4",
4242
"extend2": "^4.0.0",

site/docs/basics/plugin.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Specific consolidation rules can be found in [Configuration](./config.md).
167167
  - [multipart](https://github.com/eggjs/egg-multipart) File Streaming Upload
168168
  - [security](https://github.com/eggjs/security) Security
169169
  - [development](https://github.com/eggjs/development) Development Environment Configuration
170-
  - [logrotator](https://github.com/eggjs/egg-logrotator) Log segmentation
170+
  - [logrotator](https://github.com/eggjs/logrotator) Log segmentation
171171
  - [schedule](https://github.com/eggjs/schedule) Timing tasks
172172
  - [static](https://github.com/eggjs/static) Static server
173173
  - [jsonp](https://github.com/eggjs/jsonp) jsonp support

site/docs/basics/plugin.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ exports.mysql = {
167167
- [multipart](https://github.com/eggjs/egg-multipart) 文件流式上传
168168
- [security](https://github.com/eggjs/security) 安全
169169
- [development](https://github.com/eggjs/development) 开发环境配置
170-
- [logrotator](https://github.com/eggjs/egg-logrotator) 日志切分
170+
- [logrotator](https://github.com/eggjs/logrotator) 日志切分
171171
- [schedule](https://github.com/eggjs/schedule) 定时任务
172172
- [static](https://github.com/eggjs/static) 静态服务器
173173
- [jsonp](https://github.com/eggjs/jsonp) jsonp 支持

site/docs/core/logger.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ Performance is what we always consider as important part in our services so that
312312

313313
## Log Sharding
314314

315-
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.
315+
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.
316316

317317
### Daily Sharding
318318

@@ -369,4 +369,4 @@ Generally, requests are frequent events to Web services, so writing logs into di
369369

370370
> Logs will be firstly transferred into memory, and then Egg will asynchronously write them into files by second.
371371
372-
More about [egg-logger](https://github.com/eggjs/egg-logger) and [egg-logrotator](https://github.com/eggjs/egg-logrotator)
372+
More about [egg-logger](https://github.com/eggjs/egg-logger) and [@eggjs/logrotator](https://github.com/eggjs/logrotator)

site/docs/core/logger.zh-CN.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,10 @@ app.getLogger('errorLogger').set('remote', new RemoteErrorTransport({ level: 'ER
306306
```
307307

308308
上述代码示例中,虽然比较简单,但是在实际使用时需要考虑性能问题。通常采取先暂存至内存,再定时上传的策略,以此优化性能。
309+
309310
## 日志切割
310311

311-
企业级日志一个最常见的需求之一是对日志进行自动切割,以方便管理。框架对日志切割的支持由 [egg-logrotator](https://github.com/eggjs/egg-logrotator) 插件提供。
312+
企业级日志一个最常见的需求之一是对日志进行自动切割,以方便管理。框架对日志切割的支持由 [@eggjs/logrotator](https://github.com/eggjs/logrotator) 插件提供。
312313

313314
### 按天切割
314315

@@ -369,4 +370,4 @@ module.exports = (appInfo) => {
369370

370371
> 日志同步写入内存,异步每隔一段时间(默认 1 秒)进行刷盘。
371372
372-
更多细节,请参考 [egg-logger](https://github.com/eggjs/egg-logger)[egg-logrotator](https://github.com/eggjs/egg-logrotator)
373+
更多细节,请参考 [egg-logger](https://github.com/eggjs/egg-logger)[@eggjs/logrotator](https://github.com/eggjs/logrotator)

src/config/plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default {
8383
*/
8484
logrotator: {
8585
enable: true,
86-
package: 'egg-logrotator',
86+
package: '@eggjs/logrotator',
8787
},
8888

8989
/**

src/lib/egg.ts

+3
Original file line numberDiff line numberDiff line change
@@ -698,5 +698,8 @@ declare module '@eggjs/core' {
698698
createAnonymousContext(req?: any): EggContext;
699699
runInAnonymousContextScope(scope: (ctx: Context) => Promise<void>, req?: unknown): Promise<void>;
700700
readonly messenger: IMessenger;
701+
Subscription: typeof BaseContextClass;
702+
BaseHookClass: typeof BaseHookClass;
703+
Boot: typeof BaseHookClass;
701704
}
702705
}

src/lib/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import '@eggjs/security';
2626
import '@eggjs/schedule';
2727
import '@eggjs/session';
2828
import '@eggjs/onerror';
29+
import '@eggjs/logrotator';
30+
2931
export type {
3032
EggAppInfo,
3133
} from '@eggjs/core';

test/index.test-d.ts

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expectType } from 'tsd';
22
import { EggCore, Context } from '@eggjs/core';
3+
import { LogRotator } from '@eggjs/logrotator';
34
import {
45
Application, IBoot, ILifecycleBoot,
56
LoggerLevel,
@@ -68,6 +69,22 @@ expectType<boolean>(app.config.session.httpOnly);
6869
expectType<(err: any, ctx: any) => void>(app.config.onerror.html!);
6970
expectType<string>(app.config.onerror.errorPageUrl as string);
7071

72+
// logrotator plugin types
73+
class MyLogRotator extends LogRotator {
74+
async getRotateFiles() {
75+
return new Map();
76+
}
77+
}
78+
expectType<LogRotator>(new MyLogRotator({ app }));
79+
expectType<boolean>(app.config.logrotator.disableRotateByDay);
80+
expectType<number>(app.config.logrotator.maxDays);
81+
expectType<number>(app.config.logrotator.maxFileSize);
82+
expectType<number>(app.config.logrotator.maxFiles);
83+
expectType<number>(app.config.logrotator.rotateDuration);
84+
expectType<boolean>(app.config.logrotator.gzip);
85+
expectType<string>(app.config.logrotator.hourDelimiter);
86+
expectType<string[] | null>(app.config.logrotator.filesRotateBySize);
87+
7188
class AppBoot implements ILifecycleBoot {
7289
private readonly app: Application;
7390

test/lib/plugins/logrotator.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ describe('test/lib/plugins/logrotator.test.ts', () => {
1414
after(() => app.close());
1515

1616
it('should rotate log file default', async () => {
17-
const file = importResolve('egg-logrotator/app/schedule/rotate_by_file.js');
17+
const file = importResolve('@eggjs/logrotator/dist/esm/app/schedule/rotate_by_file.js');
1818
// console.log('job', file);
1919
await app.runSchedule(file);
2020
await scheduler.wait(1000);
2121
const files = (await fs.readdir(app.config.logger.dir)).filter(f => f.includes('.log.'));
22+
console.log(files);
2223
assert(files.length > 0);
2324
files.forEach(file => {
2425
assert(/\.log\.\d{4}-\d{2}-\d{2}$/.test(file));

0 commit comments

Comments
 (0)