Skip to content

Commit

Permalink
fix: double format issue
Browse files Browse the repository at this point in the history
`splat` of `winston` takes care of message formatting. No need to format
the message on `@midwayjs/logger` side.

Fixed #62
  • Loading branch information
ghostoy committed Jul 18, 2022
1 parent 8ebf2d4 commit d01f030
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,19 @@ export class MidwayBaseLogger extends WinstonLogger implements IMidwayLogger {

protected log(level, ...args) {
const originArgs = [...args];
let meta, msg;
let meta;
if (args.length > 1 && isPlainObject(args[args.length - 1])) {
meta = args.pop();
} else {
meta = {};
}

const last = args.pop();
if (last instanceof Error) {
msg = util.format(...args, last);
meta[ORIGIN_ERROR] = last;
} else {
msg = util.format(...args, last);
if (args.length > 0 && args[args.length - 1] instanceof Error) {
meta[ORIGIN_ERROR] = args.pop();
}

meta[ORIGIN_ARGS] = originArgs;
return super.log(level, msg, meta);
return super.log(level, ...args, meta);
}

disableConsole(): void {
Expand Down

0 comments on commit d01f030

Please sign in to comment.