From cb5c2abc99c2e222fe18621f79cb68b805678e15 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 1 Feb 2021 15:03:32 +0100 Subject: Improve parse log with sql --- scripts/parse-log.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'scripts/parse-log.ts') 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' import { CONFIG } from '../server/initializers/config' import { mtimeSortFilesDesc } from '../shared/core-utils/logs/logs' import { inspect } from 'util' +import { format as sqlFormat } from 'sql-formatter' program .option('-l, --level [level]', 'Level log (debug/info/warn/error)') @@ -21,7 +22,8 @@ const excludedKeys = { message: true, splat: true, timestamp: true, - label: true + label: true, + sql: true } function keysExcluder (key, value) { return excludedKeys[key] === true ? undefined : value @@ -32,6 +34,17 @@ const loggerFormat = winston.format.printf((info) => { if (additionalInfos === '{}') additionalInfos = '' else additionalInfos = ' ' + additionalInfos + if (info.sql) { + if (CONFIG.LOG.PRETTIFY_SQL) { + additionalInfos += '\n' + sqlFormat(info.sql, { + language: 'sql', + ident: ' ' + }) + } else { + additionalInfos += ' - ' + info.sql + } + } + return `[${info.label}] ${toTimeFormat(info.timestamp)} ${info.level}: ${info.message}${additionalInfos}` }) -- cgit v1.2.3