aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/parse-log.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-16 17:29:05 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:52 +0100
commit41dbdb8acff3ac56187e8149eab0ff82e2377597 (patch)
treeeb1636d26ebccdbd3a60bc5ee2452cfb552f83f9 /scripts/parse-log.ts
parent4610bc5b12eaa4bfd64fe3fd70c65e5b722aa22d (diff)
downloadPeerTube-41dbdb8acff3ac56187e8149eab0ff82e2377597.tar.gz
PeerTube-41dbdb8acff3ac56187e8149eab0ff82e2377597.tar.zst
PeerTube-41dbdb8acff3ac56187e8149eab0ff82e2377597.zip
Add script to parse log files
Diffstat (limited to 'scripts/parse-log.ts')
-rwxr-xr-xscripts/parse-log.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/scripts/parse-log.ts b/scripts/parse-log.ts
new file mode 100755
index 000000000..81a22f7a0
--- /dev/null
+++ b/scripts/parse-log.ts
@@ -0,0 +1,42 @@
1import { createReadStream } from 'fs'
2import { join } from 'path'
3import { createInterface } from 'readline'
4import * as winston from 'winston'
5import { readFileBufferPromise } from '../server/helpers/core-utils'
6import { CONFIG } from '../server/initializers/constants'
7
8const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
9
10const logger = new winston.Logger({
11 transports: [
12 new winston.transports.Console({
13 level: 'debug',
14 label: label,
15 handleExceptions: true,
16 humanReadableUnhandledException: true,
17 json: false,
18 colorize: true,
19 prettyPrint: true
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)
41 logLevels[log.level](log.message)
42})