import { join } from 'path'
import { createInterface } from 'readline'
import * as winston from 'winston'
-import { labelFormatter, loggerFormat, timestampFormatter } from '../server/helpers/logger'
+import { labelFormatter } from '../server/helpers/logger'
import { CONFIG } from '../server/initializers/constants'
+const excludedKeys = {
+ level: true,
+ message: true,
+ splat: true,
+ timestamp: true,
+ label: true
+}
+function keysExcluder (key, value) {
+ return excludedKeys[key] === true ? undefined : value
+}
+
+const loggerFormat = winston.format.printf((info) => {
+ let additionalInfos = JSON.stringify(info, keysExcluder, 2)
+ if (additionalInfos === '{}') additionalInfos = ''
+ else additionalInfos = ' ' + additionalInfos
+
+ return `[${info.label}] ${toTimeFormat(info.timestamp)} ${info.level}: ${info.message}${additionalInfos}`
+})
+
const logger = new winston.createLogger({
transports: [
new winston.transports.Console({
level: 'debug',
stderrLevels: [],
format: winston.format.combine(
- timestampFormatter,
winston.format.splat(),
labelFormatter,
winston.format.colorize(),
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()
+}