eggjs / eggjs/egg

定时任务内调用app.logger.info()方法会被划入到上下文日志,而不是应用日志的bug

Open
#5,603 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
19k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

### 在此输入你需要反馈的 Bug 具体信息(Bug in Detail):

1,我在定时任务task()方法内调用了app.logger.info()函数

2,预期:生成应用级别的日志,进入 `exports.logger = { formatter(meta) { }}` 的 formatter函数进行格式化日志

3,实际:生成上下文级别的日志,进入 `exports.logger = { contextFormatter(meta) { }}` 的 contextFormatter函数进行格式化日志

### 可复现问题的仓库地址(Reproduction Repo)

`
// schedule/test.js
module.exports = (app) => {
return {
schedule: {
type: 'worker',
immediate: true
},
async task (ctx) {
app.logger.info('应用日志');
}
}
}

// config/config.default.js
exports.logger = {
formatter(meta) {
const logInfo = {
type: 'application'
}
return JSON.stringify(logInfo);
},
contextFormatter(meta) {
const logInfo = {
type: 'context'
}
return JSON.stringify(logInfo);
}
}
`

### Node 版本号:

20.19.4

### Eggjs 版本号:

^3.30.1

### 相关插件名称与版本号(PlugIn and Name):

egg-scripts, ^3.1.0

### 操作平台与版本号(Platform and Version):

windows 11

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.