X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Flogger.ts;h=a112fd30006b1d2f7706c5946d386261d6b23b61;hb=1bcb03a100d172903b877d6a0e4ed11d63b14f3d;hp=f1808849ee2ece2e1dc5a37eb26ab09a9976c0fe;hpb=2a6cf69cffb83d0fbd73c4a0aabbb94df47b06c8;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index f1808849e..a112fd300 100644 --- a/server/helpers/logger.ts +++ b/server/helpers/logger.ts @@ -27,6 +27,14 @@ function getLoggerReplacer () { seen.add(value) } + if (value instanceof Set) { + return Array.from(value) + } + + if (value instanceof Map) { + return Array.from(value.entries()) + } + if (value instanceof Error) { const error = {} @@ -40,7 +48,9 @@ function getLoggerReplacer () { } const consoleLoggerFormat = winston.format.printf(info => { - const obj = omit(info, 'label', 'timestamp', 'level', 'message', 'sql') + const toOmit = [ 'label', 'timestamp', 'level', 'message', 'sql', 'tags' ] + + const obj = omit(info, ...toOmit) let additionalInfos = JSON.stringify(obj, getLoggerReplacer(), 2) @@ -48,10 +58,14 @@ const consoleLoggerFormat = winston.format.printf(info => { else additionalInfos = ' ' + additionalInfos if (info.sql) { - additionalInfos += '\n' + sqlFormat(info.sql, { - language: 'sql', - ident: ' ' - }) + if (CONFIG.LOG.PRETTIFY_SQL) { + additionalInfos += '\n' + sqlFormat(info.sql, { + language: 'sql', + indent: ' ' + }) + } else { + additionalInfos += ' - ' + info.sql + } } return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}` @@ -136,6 +150,13 @@ const bunyanLogger = { error: bunyanLogFactory('error'), fatal: bunyanLogFactory('error') } + +function loggerTagsFactory (...defaultTags: string[]) { + return (...tags: string[]) => { + return { tags: defaultTags.concat(tags) } + } +} + // --------------------------------------------------------------------------- export { @@ -145,5 +166,6 @@ export { consoleLoggerFormat, jsonLoggerFormat, logger, + loggerTagsFactory, bunyanLogger }