Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b8a60ca

Browse files
committedJul 28, 2022
fix: double format issue
`splat` of `winston` takes care of message formatting. No need to format the message on `@midwayjs/logger` side. Fixed #62
1 parent d2977ce commit b8a60ca

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed
 

‎src/logger/logger.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,19 @@ export class MidwayBaseLogger extends WinstonLogger implements IMidwayLogger {
140140

141141
protected log(level, ...args) {
142142
const originArgs = [...args];
143-
let meta, msg;
143+
let meta;
144144
if (args.length > 1 && isPlainObject(args[args.length - 1])) {
145145
meta = args.pop();
146146
} else {
147147
meta = {};
148148
}
149149

150-
const last = args.pop();
151-
if (last instanceof Error) {
152-
msg = util.format(...args, last);
153-
meta[ORIGIN_ERROR] = last;
154-
} else {
155-
msg = util.format(...args, last);
150+
if (args.length > 0 && args[args.length - 1] instanceof Error) {
151+
meta[ORIGIN_ERROR] = args.pop();
156152
}
157153

158154
meta[ORIGIN_ARGS] = originArgs;
159-
return super.log(level, msg, meta);
155+
return super.log(level, ...args, meta);
160156
}
161157

162158
disableConsole(): void {

0 commit comments

Comments
 (0)
Please sign in to comment.