Skip to content

Commit

Permalink
Fix winston logging to be primarily single-line (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
Throne3d authored Aug 9, 2020
1 parent 91ad0b1 commit ee2d70f
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import winston, { format } from 'winston';
import { inspect } from 'util';

function simpleInspect(value) {
if (typeof value === 'string') return value;
return inspect(value, { depth: null });
}

function formatter(info) {
const stringifiedRest = inspect(
{
...info,
level: undefined,
message: undefined,
splat: undefined
},
{ depth: null }
);
const splat = info[Symbol.for('splat')] || [];
const stringifiedRest = splat.length > 0 ? ` ${splat.map(simpleInspect).join(' ')}` : '';

const padding = (info.padding && info.padding[info.level]) || '';
if (stringifiedRest !== '{}') {
return `${info.timestamp} ${info.level}:${padding} ${info.message} ${stringifiedRest}`;
}

return `${info.timestamp} ${info.level}:${padding} ${info.message}`;
return `${info.timestamp} ${info.level}:${padding} ${info.message}${stringifiedRest}`;
}

const logger = winston.createLogger({
Expand All @@ -26,7 +20,7 @@ const logger = winston.createLogger({
format: format.combine(
format.colorize(),
format.timestamp(),
format.printf(formatter)
format.printf(formatter),
)
});

Expand Down

0 comments on commit ee2d70f

Please sign in to comment.