aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-19 13:58:13 +0100
committerChocobozzz <me@florianbigard.com>2018-01-19 13:58:13 +0100
commit23e27dd53599be65b2dc2968448ce155a00a96c9 (patch)
treecd7e5c88a345584a25c7ea03a81332b804d082d6 /scripts
parentc7a9f34f7229529ea726de13867f87c0a8dd3007 (diff)
downloadPeerTube-23e27dd53599be65b2dc2968448ce155a00a96c9.tar.gz
PeerTube-23e27dd53599be65b2dc2968448ce155a00a96c9.tar.zst
PeerTube-23e27dd53599be65b2dc2968448ce155a00a96c9.zip
Add ability to configure log level
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/parse-log.ts39
1 files changed, 18 insertions, 21 deletions
diff --git a/scripts/parse-log.ts b/scripts/parse-log.ts
index e2c42bf4c..7e804b3f9 100755
--- a/scripts/parse-log.ts
+++ b/scripts/parse-log.ts
@@ -2,34 +2,34 @@ import { createReadStream } from 'fs'
2import { join } from 'path' 2import { join } from 'path'
3import { createInterface } from 'readline' 3import { createInterface } from 'readline'
4import * as winston from 'winston' 4import * as winston from 'winston'
5import { labelFormatter, loggerFormat, timestampFormatter } from '../server/helpers/logger'
5import { CONFIG } from '../server/initializers/constants' 6import { CONFIG } from '../server/initializers/constants'
6 7
7const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT 8const logger = new winston.createLogger({
8
9const logger = new winston.Logger({
10 transports: [ 9 transports: [
11 new winston.transports.Console({ 10 new winston.transports.Console({
12 level: 'debug', 11 level: 'debug',
13 label: label, 12 stderrLevels: [],
14 handleExceptions: true, 13 format: winston.format.combine(
15 humanReadableUnhandledException: true, 14 timestampFormatter,
16 json: false, 15 winston.format.splat(),
17 colorize: true, 16 labelFormatter,
18 prettyPrint: true, 17 winston.format.colorize(),
19 stderrLevels: [] 18 loggerFormat
19 )
20 }) 20 })
21 ], 21 ],
22 exitOnError: true 22 exitOnError: true
23}) 23})
24 24
25const logLevels = { 25const logLevels = {
26 error: logger.error, 26 error: logger.error.bind(logger),
27 warn: logger.warn, 27 warn: logger.warn.bind(logger),
28 info: logger.info, 28 info: logger.info.bind(logger),
29 debug: logger.debug 29 debug: logger.debug.bind(logger)
30} 30}
31 31
32const path = join(CONFIG.STORAGE.LOG_DIR, 'all-logs.log') 32const path = join(CONFIG.STORAGE.LOG_DIR, 'peertube.log')
33console.log('Opening %s.', path) 33console.log('Opening %s.', path)
34 34
35const rl = createInterface({ 35const rl = createInterface({
@@ -38,11 +38,8 @@ const rl = createInterface({
38 38
39rl.on('line', line => { 39rl.on('line', line => {
40 const log = JSON.parse(line) 40 const log = JSON.parse(line)
41 const additionalInfo: any = {} 41 // Don't know why but loggerFormat does not remove splat key
42 42 Object.assign(log, { splat: undefined })
43 Object.keys(log).forEach(logKey => {
44 if (logKey !== 'message' && logKey !== 'level') additionalInfo[logKey] = log[logKey]
45 })
46 43
47 logLevels[log.level](log.message, additionalInfo) 44 logLevels[log.level](log)
48}) 45})