]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/parse-log.ts
Add delete button to my videos
[github/Chocobozzz/PeerTube.git] / scripts / parse-log.ts
CommitLineData
41dbdb8a
C
1import { createReadStream } from 'fs'
2import { join } from 'path'
3import { createInterface } from 'readline'
4import * as winston from 'winston'
41dbdb8a
C
5import { CONFIG } from '../server/initializers/constants'
6
7const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
8
9const logger = new winston.Logger({
10 transports: [
11 new winston.transports.Console({
12 level: 'debug',
13 label: label,
14 handleExceptions: true,
15 humanReadableUnhandledException: true,
16 json: false,
17 colorize: true,
c46edbc2
C
18 prettyPrint: true,
19 stderrLevels: []
41dbdb8a
C
20 })
21 ],
22 exitOnError: true
23})
24
25const logLevels = {
26 error: logger.error,
27 warn: logger.warn,
28 info: logger.info,
29 debug: logger.debug
30}
31
32const path = join(CONFIG.STORAGE.LOG_DIR, 'all-logs.log')
33console.log('Opening %s.', path)
34
35const rl = createInterface({
36 input: createReadStream(path)
37})
38
39rl.on('line', line => {
40 const log = JSON.parse(line)
afffe988
C
41 const additionalInfo: any = {}
42
43 Object.keys(log).forEach(logKey => {
44 if (logKey !== 'message' && logKey !== 'level') additionalInfo[logKey] = log[logKey]
45 })
46
47 logLevels[log.level](log.message, additionalInfo)
41dbdb8a 48})