X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Flogger.ts;h=7d1d72f29d8b1d1fae4b858304777ecf1b11a152;hb=276d03ed1a469fd4e3579f92392b6f9a1567d1ca;hp=6a02f680abbb4437276b046b1d877be6a0bc9c96;hpb=23e27dd53599be65b2dc2968448ce155a00a96c9;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index 6a02f680a..7d1d72f29 100644 --- a/server/helpers/logger.ts +++ b/server/helpers/logger.ts @@ -21,11 +21,19 @@ 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 - return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message} ${additionalInfos}` + if (info.message && info.message.stack !== undefined) info.message = info.message.stack + 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({ @@ -47,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 ) }) ], @@ -70,6 +78,6 @@ const logger = new winston.createLogger({ export { timestampFormatter, labelFormatter, - loggerFormat, + consoleLoggerFormat, logger }