aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-03-05 13:26:02 +0100
committerChocobozzz <me@florianbigard.com>2021-03-24 18:18:40 +0100
commit452b3bea082481b84537e55c7cedc1e24860d543 (patch)
treeedd6a3eb988b093abbcde9fd1890b7fa69d8f25f /scripts
parentd00717523890dfc90859a27921f20d79d101ae6e (diff)
downloadPeerTube-452b3bea082481b84537e55c7cedc1e24860d543.tar.gz
PeerTube-452b3bea082481b84537e55c7cedc1e24860d543.tar.zst
PeerTube-452b3bea082481b84537e55c7cedc1e24860d543.zip
Introduce tags to the logger
That could help to filter unneeded logs and/or select particular components
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/parse-log.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/scripts/parse-log.ts b/scripts/parse-log.ts
index 3679dab74..5f4480c88 100755
--- a/scripts/parse-log.ts
+++ b/scripts/parse-log.ts
@@ -15,6 +15,8 @@ import { format as sqlFormat } from 'sql-formatter'
15program 15program
16 .option('-l, --level [level]', 'Level log (debug/info/warn/error)') 16 .option('-l, --level [level]', 'Level log (debug/info/warn/error)')
17 .option('-f, --files [file...]', 'Files to parse. If not provided, the script will parse the latest log file from config)') 17 .option('-f, --files [file...]', 'Files to parse. If not provided, the script will parse the latest log file from config)')
18 .option('-t, --tags [tags...]', 'Display only lines with these tags')
19 .option('-nt, --not-tags [tags...]', 'Donrt display lines containing these tags')
18 .parse(process.argv) 20 .parse(process.argv)
19 21
20const options = program.opts() 22const options = program.opts()
@@ -24,6 +26,7 @@ const excludedKeys = {
24 message: true, 26 message: true,
25 splat: true, 27 splat: true,
26 timestamp: true, 28 timestamp: true,
29 tags: true,
27 label: true, 30 label: true,
28 sql: true 31 sql: true
29} 32}
@@ -93,6 +96,14 @@ function run () {
93 rl.on('line', line => { 96 rl.on('line', line => {
94 try { 97 try {
95 const log = JSON.parse(line) 98 const log = JSON.parse(line)
99 if (options.tags && !containsTags(log.tags, options.tags)) {
100 return
101 }
102
103 if (options.notTags && containsTags(log.tags, options.notTags)) {
104 return
105 }
106
96 // Don't know why but loggerFormat does not remove splat key 107 // Don't know why but loggerFormat does not remove splat key
97 Object.assign(log, { splat: undefined }) 108 Object.assign(log, { splat: undefined })
98 109
@@ -131,3 +142,15 @@ function toTimeFormat (time: string) {
131 142
132 return new Date(timestamp).toISOString() 143 return new Date(timestamp).toISOString()
133} 144}
145
146function containsTags (loggerTags: string[], optionsTags: string[]) {
147 if (!loggerTags) return false
148
149 for (const lt of loggerTags) {
150 for (const ot of optionsTags) {
151 if (lt === ot) return true
152 }
153 }
154
155 return false
156}