X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Flogger.ts;h=7d1d72f29d8b1d1fae4b858304777ecf1b11a152;hb=276d03ed1a469fd4e3579f92392b6f9a1567d1ca;hp=bcd4885af961a9a1a087ab98806fc46bb158da36;hpb=3bf1ec2ebb6da3ffbfb2af505268a47d38956d28;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index bcd4885af..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 }