diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-01 15:03:32 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-02-01 15:04:45 +0100 |
commit | cb5c2abc99c2e222fe18621f79cb68b805678e15 (patch) | |
tree | efba65b136bc31d3feca05fcf2506303ca18c2e6 /scripts/parse-log.ts | |
parent | 6949a1a1113cc6af3442dc3d5446b8fe6143f28e (diff) | |
download | PeerTube-cb5c2abc99c2e222fe18621f79cb68b805678e15.tar.gz PeerTube-cb5c2abc99c2e222fe18621f79cb68b805678e15.tar.zst PeerTube-cb5c2abc99c2e222fe18621f79cb68b805678e15.zip |
Improve parse log with sql
Diffstat (limited to 'scripts/parse-log.ts')
-rwxr-xr-x | scripts/parse-log.ts | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/scripts/parse-log.ts b/scripts/parse-log.ts index 065fe7e82..045348e86 100755 --- a/scripts/parse-log.ts +++ b/scripts/parse-log.ts | |||
@@ -10,6 +10,7 @@ import { labelFormatter } from '../server/helpers/logger' | |||
10 | import { CONFIG } from '../server/initializers/config' | 10 | import { CONFIG } from '../server/initializers/config' |
11 | import { mtimeSortFilesDesc } from '../shared/core-utils/logs/logs' | 11 | import { mtimeSortFilesDesc } from '../shared/core-utils/logs/logs' |
12 | import { inspect } from 'util' | 12 | import { inspect } from 'util' |
13 | import { format as sqlFormat } from 'sql-formatter' | ||
13 | 14 | ||
14 | program | 15 | program |
15 | .option('-l, --level [level]', 'Level log (debug/info/warn/error)') | 16 | .option('-l, --level [level]', 'Level log (debug/info/warn/error)') |
@@ -21,7 +22,8 @@ const excludedKeys = { | |||
21 | message: true, | 22 | message: true, |
22 | splat: true, | 23 | splat: true, |
23 | timestamp: true, | 24 | timestamp: true, |
24 | label: true | 25 | label: true, |
26 | sql: true | ||
25 | } | 27 | } |
26 | function keysExcluder (key, value) { | 28 | function keysExcluder (key, value) { |
27 | return excludedKeys[key] === true ? undefined : value | 29 | return excludedKeys[key] === true ? undefined : value |
@@ -32,6 +34,17 @@ const loggerFormat = winston.format.printf((info) => { | |||
32 | if (additionalInfos === '{}') additionalInfos = '' | 34 | if (additionalInfos === '{}') additionalInfos = '' |
33 | else additionalInfos = ' ' + additionalInfos | 35 | else additionalInfos = ' ' + additionalInfos |
34 | 36 | ||
37 | if (info.sql) { | ||
38 | if (CONFIG.LOG.PRETTIFY_SQL) { | ||
39 | additionalInfos += '\n' + sqlFormat(info.sql, { | ||
40 | language: 'sql', | ||
41 | ident: ' ' | ||
42 | }) | ||
43 | } else { | ||
44 | additionalInfos += ' - ' + info.sql | ||
45 | } | ||
46 | } | ||
47 | |||
35 | return `[${info.label}] ${toTimeFormat(info.timestamp)} ${info.level}: ${info.message}${additionalInfos}` | 48 | return `[${info.label}] ${toTimeFormat(info.timestamp)} ${info.level}: ${info.message}${additionalInfos}` |
36 | }) | 49 | }) |
37 | 50 | ||