1
0
Fork 0
peertube/scripts/parse-log.ts

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2017-11-16 11:29:05 -05:00
import { createReadStream } from 'fs'
import { join } from 'path'
import { createInterface } from 'readline'
import * as winston from 'winston'
2018-01-19 07:58:13 -05:00
import { labelFormatter, loggerFormat, timestampFormatter } from '../server/helpers/logger'
2017-11-16 11:29:05 -05:00
import { CONFIG } from '../server/initializers/constants'
2018-01-19 07:58:13 -05:00
const logger = new winston.createLogger({
2017-11-16 11:29:05 -05:00
transports: [
new winston.transports.Console({
level: 'debug',
2018-01-19 07:58:13 -05:00
stderrLevels: [],
format: winston.format.combine(
timestampFormatter,
winston.format.splat(),
labelFormatter,
winston.format.colorize(),
loggerFormat
)
2017-11-16 11:29:05 -05:00
})
],
exitOnError: true
})
const logLevels = {
2018-01-19 07:58:13 -05:00
error: logger.error.bind(logger),
warn: logger.warn.bind(logger),
info: logger.info.bind(logger),
debug: logger.debug.bind(logger)
2017-11-16 11:29:05 -05:00
}
2018-01-19 07:58:13 -05:00
const path = join(CONFIG.STORAGE.LOG_DIR, 'peertube.log')
2017-11-16 11:29:05 -05:00
console.log('Opening %s.', path)
const rl = createInterface({
input: createReadStream(path)
})
rl.on('line', line => {
const log = JSON.parse(line)
2018-01-19 07:58:13 -05:00
// Don't know why but loggerFormat does not remove splat key
Object.assign(log, { splat: undefined })
2017-11-17 05:35:10 -05:00
2018-01-19 07:58:13 -05:00
logLevels[log.level](log)
2017-11-16 11:29:05 -05:00
})