X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Flogger.ts;h=29e06860dbf9ca0604805dc94bfeab2e75aa1d46;hb=463206948d6a9d46e7e68d55c7b763e601ecc870;hp=0548dfd5ba4a6e1e4c4993ee21e95f366df0cf86;hpb=1e743faafeed89af13ee9dd3d62c1ceb696779cd;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index 0548dfd5b..29e06860d 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,8 +48,7 @@ function getLoggerReplacer () { } const consoleLoggerFormat = winston.format.printf(info => { - const toOmit = [ 'label', 'timestamp', 'level', 'message' ] - if (CONFIG.LOG.PRETTIFY_SQL) toOmit.push('sql') + const toOmit = [ 'label', 'timestamp', 'level', 'message', 'sql', 'tags' ] const obj = omit(info, ...toOmit) @@ -50,11 +57,15 @@ const consoleLoggerFormat = winston.format.printf(info => { if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = '' else additionalInfos = ' ' + additionalInfos - if (CONFIG.LOG.PRETTIFY_SQL && info.sql) { - additionalInfos += '\n' + sqlFormat(info.sql, { - language: 'sql', - ident: ' ' - }) + if (info.sql) { + 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}` @@ -139,14 +150,25 @@ const bunyanLogger = { error: bunyanLogFactory('error'), fatal: bunyanLogFactory('error') } + +type LoggerTagsFn = (...tags: string[]) => { tags: string[] } +function loggerTagsFactory (...defaultTags: string[]): LoggerTagsFn { + return (...tags: string[]) => { + return { tags: defaultTags.concat(tags) } + } +} + // --------------------------------------------------------------------------- export { + LoggerTagsFn, + buildLogger, timestampFormatter, labelFormatter, consoleLoggerFormat, jsonLoggerFormat, logger, + loggerTagsFactory, bunyanLogger }