X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Flogger.ts;h=0548dfd5ba4a6e1e4c4993ee21e95f366df0cf86;hb=1e743faafeed89af13ee9dd3d62c1ceb696779cd;hp=9553f70e80d60986149c7eb8726ea6d2e7c84f31;hpb=610d0be13b3d01f653ef269271dd667a57c85ef2;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index 9553f70e8..0548dfd5b 100644 --- a/server/helpers/logger.ts +++ b/server/helpers/logger.ts @@ -1,10 +1,11 @@ // Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ import { mkdirpSync } from 'fs-extra' +import { omit } from 'lodash' import * as path from 'path' +import { format as sqlFormat } from 'sql-formatter' import * as winston from 'winston' import { FileTransportOptions } from 'winston/lib/winston/transports' import { CONFIG } from '../initializers/config' -import { omit } from 'lodash' import { LOG_FILENAME } from '../initializers/constants' const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT @@ -18,6 +19,8 @@ function getLoggerReplacer () { // Thanks: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value#Examples return (key: string, value: any) => { + if (key === 'cert') return 'Replaced by the logger to avoid large log message' + if (typeof value === 'object' && value !== null) { if (seen.has(value)) return @@ -37,13 +40,23 @@ function getLoggerReplacer () { } const consoleLoggerFormat = winston.format.printf(info => { - const obj = omit(info, 'label', 'timestamp', 'level', 'message') + const toOmit = [ 'label', 'timestamp', 'level', 'message' ] + if (CONFIG.LOG.PRETTIFY_SQL) toOmit.push('sql') + + const obj = omit(info, ...toOmit) let additionalInfos = JSON.stringify(obj, getLoggerReplacer(), 2) if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = '' else additionalInfos = ' ' + additionalInfos + if (CONFIG.LOG.PRETTIFY_SQL && info.sql) { + additionalInfos += '\n' + sqlFormat(info.sql, { + language: 'sql', + ident: ' ' + }) + } + return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}` })