From: Chocobozzz Date: Thu, 8 Mar 2018 17:16:15 +0000 (+0100) Subject: Fix logging timestamp X-Git-Tag: v1.0.0-alpha.6~2 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0647f472bc45d82a34e509434c112326499bbe17;p=oweals%2Fpeertube.git Fix logging timestamp --- diff --git a/scripts/parse-log.ts b/scripts/parse-log.ts index 9429512b7..2c5ef696d 100755 --- a/scripts/parse-log.ts +++ b/scripts/parse-log.ts @@ -21,7 +21,7 @@ const loggerFormat = winston.format.printf((info) => { if (additionalInfos === '{}') additionalInfos = '' else additionalInfos = ' ' + additionalInfos - return `[${info.label}] ${new Date(info.timestamp).toISOString()} ${info.level}: ${info.message}${additionalInfos}` + return `[${info.label}] ${toTimeFormat(info.timestamp)} ${info.level}: ${info.message}${additionalInfos}` }) const logger = new winston.createLogger({ @@ -61,3 +61,11 @@ rl.on('line', line => { logLevels[log.level](log) }) + +function toTimeFormat (time: string) { + const timestamp = Date.parse(time) + + if (isNaN(timestamp) === true) return 'Unknown date' + + return new Date(timestamp).toISOString() +} diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index a4e5b58a4..e0b904950 100644 --- a/server/helpers/logger.ts +++ b/server/helpers/logger.ts @@ -37,7 +37,7 @@ const jsonLoggerFormat = winston.format.printf(info => { }) const timestampFormatter = winston.format.timestamp({ - format: 'YYYY-MM-dd HH:mm:ss.SSS' + format: 'YYYY-MM-DD HH:mm:ss.SSS' }) const labelFormatter = winston.format.label({ label @@ -52,7 +52,7 @@ const logger = new winston.createLogger({ maxsize: 5242880, maxFiles: 5, format: winston.format.combine( - timestampFormatter, + winston.format.timestamp(), labelFormatter, winston.format.splat(), jsonLoggerFormat