From d5b7d9110dd637a7f67ce9e430145314812a8df1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 26 Mar 2018 15:54:13 +0200 Subject: Fix error logging --- server/helpers/database-utils.ts | 2 +- server/helpers/ffmpeg-utils.ts | 4 ++-- server/helpers/logger.ts | 16 +++++++++++++--- server/helpers/peertube-crypto.ts | 2 +- server/helpers/utils.ts | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index d09b4b245..47a0abfd2 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts @@ -16,7 +16,7 @@ function retryTransactionWrapper ( .catch(err => callback(err)) }) .catch(err => { - logger.error(options.errorMessage, err) + logger.error(options.errorMessage, { err }) throw err }) } diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index 8f9a03c26..bfc942fa3 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts @@ -64,12 +64,12 @@ async function generateImageFromVideoFile (fromPath: string, folder: string, ima const destination = join(folder, imageName) await processImage({ path: pendingImagePath }, destination, size) } catch (err) { - logger.error('Cannot generate image from video %s.', fromPath, err) + logger.error('Cannot generate image from video %s.', fromPath, { err }) try { await unlinkPromise(pendingImagePath) } catch (err) { - logger.debug('Cannot remove pending image path after generation error.', err) + logger.debug('Cannot remove pending image path after generation error.', { err }) } } } diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index 7968b5ec9..d92381a2c 100644 --- a/server/helpers/logger.ts +++ b/server/helpers/logger.ts @@ -18,7 +18,11 @@ const excludedKeys = { label: true } function keysExcluder (key, value) { - return excludedKeys[key] === true ? undefined : value + if (excludedKeys[key] === true) return undefined + + if (key === 'err') return value.stack + + return value } const consoleLoggerFormat = winston.format.printf(info => { @@ -30,8 +34,14 @@ const consoleLoggerFormat = winston.format.printf(info => { return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}` }) -const jsonLoggerFormat = winston.format.printf(info => { - if (info.message && info.message.stack !== undefined) info.message = info.message.stack +const jsonLoggerFormat = winston.format.printf(infoArg => { + let info = infoArg.err + ? Object.assign({}, infoArg, { err: infoArg.err.stack }) + : infoArg + + if (infoArg.message && infoArg.message.stack !== undefined) { + info = Object.assign({}, info, { message: infoArg.message.stack }) + } return JSON.stringify(info) }) diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index 313c12e26..5c182961d 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts @@ -35,7 +35,7 @@ function isSignatureVerified (fromActor: ActorModel, signedDocument: object) { return jsig.promises.verify(signedDocument, options) .catch(err => { - logger.error('Cannot check signature.', err) + logger.error('Cannot check signature.', { err }) return false }) } diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index 3b618360b..c58117219 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -44,7 +44,7 @@ function createReqFiles ( try { randomString = await generateRandomString(16) } catch (err) { - logger.error('Cannot generate random string for file name.', err) + logger.error('Cannot generate random string for file name.', { err }) randomString = 'fake-random-string' } -- cgit v1.2.3