Skip to content

Commit 0fea660

Browse files
authored
fix(web): default app logger name error in cluster mode (#3455)
* fix: core logger missing file log name * Revert "fix: core logger missing file log name" This reverts commit 5a42c92. * fix: overwrite default app logger name when add object * docs: update logger
1 parent 5d1e834 commit 0fea660

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

packages/web/src/logger.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ class MidwayLoggers extends Map<string, ILogger> {
104104
// 这里属于 hack 了,cluster 模式下会先走这里,找不到默认值
105105
// 先合并一遍默认配置
106106
configService.addObject(
107-
loggers.getDefaultMidwayLoggerConfig(configService.getAppInfo())
107+
loggers.getDefaultMidwayLoggerConfig(configService.getAppInfo()),
108+
true
108109
);
109110
loggerConfig = configService.getConfiguration('midwayLogger');
110111

site/docs/logger.md

+24
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Midway 为不同场景提供了一套统一的日志接入方式。通过 `@midw
3434

3535
在大部分场景下,两个版本是兼容的,但是在配置中,会有一定的差异性,为此我们提供了一些方法来尽可能兼容老逻辑,完整的 Breaking Change 变化,请查看 [变更文档](https://github.com/midwayjs/logger/blob/main/BREAKING-3.md)
3636

37+
如果你的配置文件中有老的日志配置,可以参考 **常见问题** 进行转换。
38+
3739

3840

3941
## 日志路径和文件
@@ -936,3 +938,25 @@ const newLoggerConfig = formatLegacyLoggerOptions({
936938
注意,这个方法只能转换老的配置,如果配置中包含新老配置则新配置不会生效。
937939

938940
:::
941+
942+
比如,你的 `src/config/config.default.ts` 中如果有日志使用的是老配置,可以使用这个方法做兼容。
943+
944+
```typescript
945+
import { MidwayConfig, MidwayAppInfo } from '@midwayjs/core';
946+
import { formatLegacyLoggerOptions } from '@midwayjs/logger';
947+
948+
export default (appInfo: MidwayAppInfo) => {
949+
return {
950+
midwayLogger: {
951+
clients: {
952+
abc: logger.formatLegacyLoggerOptions({
953+
fileLogName: 'abc.log',
954+
}),
955+
}
956+
},
957+
// ...
958+
} as MidwayConfig;
959+
};
960+
961+
```
962+

site/i18n/en/docusaurus-plugin-content-docs/current/logger.md

+48-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Upgrade the dependency versions in `package.json`, pay attention to the `depende
3434

3535
In most scenarios, the two versions are compatible, but there will be certain differences in configuration. For this reason, we have provided some methods to be as compatible with the old logic as possible. For complete Breaking Change changes, please view [the change document](https://github.com/midwayjs/logger/blob/main/BREAKING-3.md).
3636

37+
If you have old log configuration in your configuration file, you can refer to **Common Problem** to convert it.
38+
3739

3840

3941
## Logger path and file
@@ -897,7 +899,7 @@ export class MainConfiguration {
897899

898900

899901

900-
## Common problem
902+
## Common Problem
901903

902904

903905

@@ -917,4 +919,48 @@ Generally speaking, the server console log (console) is closed and will only be
917919

918920
### 3. Some Docker environments fail to start
919921

920-
Check whether the user who started the current application in the directory where the log is written has permissions.
922+
Check whether the user who started the current application in the directory where the log is written has permissions.
923+
924+
925+
926+
### 4. How to convert if there is an old configuration?
927+
928+
The log library provides a conversion method to assist users in converting old configurations into new configurations.
929+
930+
```typescript
931+
import { formatLegacyLoggerOptions } from '@midwayjs/logger';
932+
933+
const newLoggerConfig = formatLegacyLoggerOptions({
934+
level: 'info',
935+
enableFile: false,
936+
disableConsole: true,
937+
enableJSON: true,
938+
});
939+
```
940+
941+
:::caution
942+
943+
Note that this method can only convert the old configuration. If the configuration contains the old and new configurations, the new configuration will not take effect.
944+
945+
:::
946+
947+
For example, if there are logs in your `src/config/config.default.ts` that use old configurations, you can use this method for compatibility.
948+
949+
```typescript
950+
import { MidwayConfig, MidwayAppInfo } from '@midwayjs/core';
951+
import { formatLegacyLoggerOptions } from '@midwayjs/logger';
952+
953+
export default (appInfo: MidwayAppInfo) => {
954+
return {
955+
midwayLogger: {
956+
clients: {
957+
abc: logger.formatLegacyLoggerOptions({
958+
fileLogName: 'abc.log',
959+
}),
960+
}
961+
},
962+
// ...
963+
} as MidwayConfig;
964+
};
965+
966+
```

0 commit comments

Comments
 (0)