aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-03-26 15:54:13 +0200
committerChocobozzz <me@florianbigard.com>2018-03-26 16:04:14 +0200
commitd5b7d9110dd637a7f67ce9e430145314812a8df1 (patch)
treed019ef5fe68b14d7e5ad11953b6c1f4811669ce6 /server/helpers
parent0dcf9a14be3f8668fe5ee65cf0365d457b4d1499 (diff)
downloadPeerTube-d5b7d9110dd637a7f67ce9e430145314812a8df1.tar.gz
PeerTube-d5b7d9110dd637a7f67ce9e430145314812a8df1.tar.zst
PeerTube-d5b7d9110dd637a7f67ce9e430145314812a8df1.zip
Fix error logging
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/database-utils.ts2
-rw-r--r--server/helpers/ffmpeg-utils.ts4
-rw-r--r--server/helpers/logger.ts16
-rw-r--r--server/helpers/peertube-crypto.ts2
-rw-r--r--server/helpers/utils.ts2
5 files changed, 18 insertions, 8 deletions
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 <T> (
16 .catch(err => callback(err)) 16 .catch(err => callback(err))
17 }) 17 })
18 .catch(err => { 18 .catch(err => {
19 logger.error(options.errorMessage, err) 19 logger.error(options.errorMessage, { err })
20 throw err 20 throw err
21 }) 21 })
22} 22}
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
64 const destination = join(folder, imageName) 64 const destination = join(folder, imageName)
65 await processImage({ path: pendingImagePath }, destination, size) 65 await processImage({ path: pendingImagePath }, destination, size)
66 } catch (err) { 66 } catch (err) {
67 logger.error('Cannot generate image from video %s.', fromPath, err) 67 logger.error('Cannot generate image from video %s.', fromPath, { err })
68 68
69 try { 69 try {
70 await unlinkPromise(pendingImagePath) 70 await unlinkPromise(pendingImagePath)
71 } catch (err) { 71 } catch (err) {
72 logger.debug('Cannot remove pending image path after generation error.', err) 72 logger.debug('Cannot remove pending image path after generation error.', { err })
73 } 73 }
74 } 74 }
75} 75}
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 = {
18 label: true 18 label: true
19} 19}
20function keysExcluder (key, value) { 20function keysExcluder (key, value) {
21 return excludedKeys[key] === true ? undefined : value 21 if (excludedKeys[key] === true) return undefined
22
23 if (key === 'err') return value.stack
24
25 return value
22} 26}
23 27
24const consoleLoggerFormat = winston.format.printf(info => { 28const consoleLoggerFormat = winston.format.printf(info => {
@@ -30,8 +34,14 @@ const consoleLoggerFormat = winston.format.printf(info => {
30 return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}` 34 return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}`
31}) 35})
32 36
33const jsonLoggerFormat = winston.format.printf(info => { 37const jsonLoggerFormat = winston.format.printf(infoArg => {
34 if (info.message && info.message.stack !== undefined) info.message = info.message.stack 38 let info = infoArg.err
39 ? Object.assign({}, infoArg, { err: infoArg.err.stack })
40 : infoArg
41
42 if (infoArg.message && infoArg.message.stack !== undefined) {
43 info = Object.assign({}, info, { message: infoArg.message.stack })
44 }
35 45
36 return JSON.stringify(info) 46 return JSON.stringify(info)
37}) 47})
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) {
35 35
36 return jsig.promises.verify(signedDocument, options) 36 return jsig.promises.verify(signedDocument, options)
37 .catch(err => { 37 .catch(err => {
38 logger.error('Cannot check signature.', err) 38 logger.error('Cannot check signature.', { err })
39 return false 39 return false
40 }) 40 })
41} 41}
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 (
44 try { 44 try {
45 randomString = await generateRandomString(16) 45 randomString = await generateRandomString(16)
46 } catch (err) { 46 } catch (err) {
47 logger.error('Cannot generate random string for file name.', err) 47 logger.error('Cannot generate random string for file name.', { err })
48 randomString = 'fake-random-string' 48 randomString = 'fake-random-string'
49 } 49 }
50 50