aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-07-12 16:21:13 +0200
committerChocobozzz <me@florianbigard.com>2022-07-12 16:23:06 +0200
commit5220859984a9a20c575a294e5825b3e0d756b03b (patch)
tree24ef9e55fcf065b92033e5cf98ecf2ceb8e5b500
parentf686f5ed0aca2c43d42779f9eb2dc1636b5bac6b (diff)
downloadPeerTube-5220859984a9a20c575a294e5825b3e0d756b03b.tar.gz
PeerTube-5220859984a9a20c575a294e5825b3e0d756b03b.tar.zst
PeerTube-5220859984a9a20c575a294e5825b3e0d756b03b.zip
Fix log parser with multiple files
-rwxr-xr-xscripts/parse-log.ts62
1 files changed, 33 insertions, 29 deletions
diff --git a/scripts/parse-log.ts b/scripts/parse-log.ts
index 7a50d9f2f..5a420a46c 100755
--- a/scripts/parse-log.ts
+++ b/scripts/parse-log.ts
@@ -76,44 +76,48 @@ run()
76 .then(() => process.exit(0)) 76 .then(() => process.exit(0))
77 .catch(err => console.error(err)) 77 .catch(err => console.error(err))
78 78
79function run () { 79async function run () {
80 return new Promise<void>(async res => { 80 const files = await getFiles()
81 const files = await getFiles()
82 81
83 for (const file of files) { 82 for (const file of files) {
84 if (file === 'peertube-audit.log') continue 83 if (file === 'peertube-audit.log') continue
85 84
86 console.log('Opening %s.', file) 85 await readFile(file)
87 86 }
88 const stream = createReadStream(file) 87}
89 88
90 const rl = createInterface({ 89function readFile (file: string) {
91 input: stream 90 console.log('Opening %s.', file)
92 })
93 91
94 rl.on('line', line => { 92 const stream = createReadStream(file)
95 try {
96 const log = JSON.parse(line)
97 if (options.tags && !containsTags(log.tags, options.tags)) {
98 return
99 }
100 93
101 if (options.notTags && containsTags(log.tags, options.notTags)) { 94 const rl = createInterface({
102 return 95 input: stream
103 } 96 })
104 97
105 // Don't know why but loggerFormat does not remove splat key 98 return new Promise<void>(res => {
106 Object.assign(log, { splat: undefined }) 99 rl.on('line', line => {
100 try {
101 const log = JSON.parse(line)
102 if (options.tags && !containsTags(log.tags, options.tags)) {
103 return
104 }
107 105
108 logLevels[log.level](log) 106 if (options.notTags && containsTags(log.tags, options.notTags)) {
109 } catch (err) { 107 return
110 console.error('Cannot parse line.', inspect(line))
111 throw err
112 } 108 }
113 })
114 109
115 stream.once('close', () => res()) 110 // Don't know why but loggerFormat does not remove splat key
116 } 111 Object.assign(log, { splat: undefined })
112
113 logLevels[log.level](log)
114 } catch (err) {
115 console.error('Cannot parse line.', inspect(line))
116 throw err
117 }
118 })
119
120 stream.once('close', () => res())
117 }) 121 })
118} 122}
119 123