X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Flogger.ts;h=d21746963d01f4b659a1fa2b34bb897f53b13727;hb=5c7d650827cc471a03e7fa18362bcbcbe5d30838;hp=8603dd76127afe0a7b253db9460e1d6cbf334b93;hpb=fcf4569f2da9ebcdc43caf8276f82098c89e5677;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index 8603dd761..d21746963 100644 --- a/server/helpers/logger.ts +++ b/server/helpers/logger.ts @@ -12,22 +12,33 @@ const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT // FIXME: use async mkdirpSync(CONFIG.STORAGE.LOG_DIR) -function loggerReplacer (key: string, value: any) { - if (value instanceof Error) { - const error = {} +function getLoggerReplacer () { + const seen = new WeakSet() - Object.getOwnPropertyNames(value).forEach(key => error[ key ] = value[ key ]) + // Thanks: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value#Examples + return (key: string, value: any) => { + if (typeof value === 'object' && value !== null) { + if (seen.has(value)) return - return error - } + seen.add(value) + } + + if (value instanceof Error) { + const error = {} + + Object.getOwnPropertyNames(value).forEach(key => error[ key ] = value[ key ]) - return value + return error + } + + return value + } } const consoleLoggerFormat = winston.format.printf(info => { const obj = omit(info, 'label', 'timestamp', 'level', 'message') - let additionalInfos = JSON.stringify(obj, loggerReplacer, 2) + let additionalInfos = JSON.stringify(obj, getLoggerReplacer(), 2) if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = '' else additionalInfos = ' ' + additionalInfos @@ -36,7 +47,7 @@ const consoleLoggerFormat = winston.format.printf(info => { }) const jsonLoggerFormat = winston.format.printf(info => { - return JSON.stringify(info, loggerReplacer) + return JSON.stringify(info, getLoggerReplacer()) }) const timestampFormatter = winston.format.timestamp({ @@ -47,7 +58,6 @@ const labelFormatter = winston.format.label({ }) const fileLoggerOptions: FileTransportOptions = { - filename: path.join(CONFIG.STORAGE.LOG_DIR, 'peertube.log'), handleExceptions: true, format: winston.format.combine(