X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Flogger.ts;h=7d1d72f29d8b1d1fae4b858304777ecf1b11a152;hb=276d03ed1a469fd4e3579f92392b6f9a1567d1ca;hp=201ea2235cd39ac36b620b7a48b6c260c9df53f6;hpb=1e9d7b60cd93ad5d1aed47fd157f1993d4b4eac0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index 201ea2235..7d1d72f29 100644 --- a/server/helpers/logger.ts +++ b/server/helpers/logger.ts @@ -21,7 +21,7 @@ function keysExcluder (key, value) { return excludedKeys[key] === true ? undefined : value } -const loggerFormat = winston.format.printf((info) => { +const consoleLoggerFormat = winston.format.printf(info => { let additionalInfos = JSON.stringify(info, keysExcluder, 2) if (additionalInfos === '{}') additionalInfos = '' else additionalInfos = ' ' + additionalInfos @@ -30,6 +30,12 @@ const loggerFormat = winston.format.printf((info) => { return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}` }) +const jsonLoggerFormat = winston.format.printf(info => { + if (info.message && info.message.stack !== undefined) info.message = info.message.stack + + return JSON.stringify(info) +}) + const timestampFormatter = winston.format.timestamp({ format: 'YYYY-MM-dd HH:mm:ss.SSS' }) @@ -49,18 +55,18 @@ const logger = new winston.createLogger({ timestampFormatter, labelFormatter, winston.format.splat(), - winston.format.json() + jsonLoggerFormat ) }), new winston.transports.Console({ - handleExceptions: true, + handleExcegiptions: true, humanReadableUnhandledException: true, format: winston.format.combine( timestampFormatter, winston.format.splat(), labelFormatter, winston.format.colorize(), - loggerFormat + consoleLoggerFormat ) }) ], @@ -72,6 +78,6 @@ const logger = new winston.createLogger({ export { timestampFormatter, labelFormatter, - loggerFormat, + consoleLoggerFormat, logger }