Fix logging timestamp
This commit is contained in:
parent
dfecb90036
commit
0647f472bc
|
@ -21,7 +21,7 @@ const loggerFormat = winston.format.printf((info) => {
|
||||||
if (additionalInfos === '{}') additionalInfos = ''
|
if (additionalInfos === '{}') additionalInfos = ''
|
||||||
else 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({
|
const logger = new winston.createLogger({
|
||||||
|
@ -61,3 +61,11 @@ rl.on('line', line => {
|
||||||
|
|
||||||
logLevels[log.level](log)
|
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()
|
||||||
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ const jsonLoggerFormat = winston.format.printf(info => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const timestampFormatter = winston.format.timestamp({
|
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({
|
const labelFormatter = winston.format.label({
|
||||||
label
|
label
|
||||||
|
@ -52,7 +52,7 @@ const logger = new winston.createLogger({
|
||||||
maxsize: 5242880,
|
maxsize: 5242880,
|
||||||
maxFiles: 5,
|
maxFiles: 5,
|
||||||
format: winston.format.combine(
|
format: winston.format.combine(
|
||||||
timestampFormatter,
|
winston.format.timestamp(),
|
||||||
labelFormatter,
|
labelFormatter,
|
||||||
winston.format.splat(),
|
winston.format.splat(),
|
||||||
jsonLoggerFormat
|
jsonLoggerFormat
|
||||||
|
|
Loading…
Reference in New Issue