Skip to content

Commit ee2d70f

Browse files
authored
Fix winston logging to be primarily single-line (#554)
1 parent 91ad0b1 commit ee2d70f

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

lib/logger.js

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
import winston, { format } from 'winston';
22
import { inspect } from 'util';
33

4+
function simpleInspect(value) {
5+
if (typeof value === 'string') return value;
6+
return inspect(value, { depth: null });
7+
}
8+
49
function formatter(info) {
5-
const stringifiedRest = inspect(
6-
{
7-
...info,
8-
level: undefined,
9-
message: undefined,
10-
splat: undefined
11-
},
12-
{ depth: null }
13-
);
10+
const splat = info[Symbol.for('splat')] || [];
11+
const stringifiedRest = splat.length > 0 ? ` ${splat.map(simpleInspect).join(' ')}` : '';
1412

1513
const padding = (info.padding && info.padding[info.level]) || '';
16-
if (stringifiedRest !== '{}') {
17-
return `${info.timestamp} ${info.level}:${padding} ${info.message} ${stringifiedRest}`;
18-
}
19-
20-
return `${info.timestamp} ${info.level}:${padding} ${info.message}`;
14+
return `${info.timestamp} ${info.level}:${padding} ${info.message}${stringifiedRest}`;
2115
}
2216

2317
const logger = winston.createLogger({
@@ -26,7 +20,7 @@ const logger = winston.createLogger({
2620
format: format.combine(
2721
format.colorize(),
2822
format.timestamp(),
29-
format.printf(formatter)
23+
format.printf(formatter),
3024
)
3125
});
3226

0 commit comments

Comments
 (0)