aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-11-05 11:08:51 +0100
committerChocobozzz <me@florianbigard.com>2019-11-05 11:08:51 +0100
commit959dbbd7bf655e9a36a310838dae75b9909f0096 (patch)
treeb7801ddcb78098fc51ecc4678074d251453bbfa3
parent5d9e4eaabe87ff1b115114b01075b9fabd2b0c5e (diff)
downloadPeerTube-959dbbd7bf655e9a36a310838dae75b9909f0096.tar.gz
PeerTube-959dbbd7bf655e9a36a310838dae75b9909f0096.tar.zst
PeerTube-959dbbd7bf655e9a36a310838dae75b9909f0096.zip
Avoid circular error in logger
-rw-r--r--server/helpers/logger.ts30
-rw-r--r--server/initializers/checker-before-init.ts4
2 files changed, 22 insertions, 12 deletions
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
12// FIXME: use async 12// FIXME: use async
13mkdirpSync(CONFIG.STORAGE.LOG_DIR) 13mkdirpSync(CONFIG.STORAGE.LOG_DIR)
14 14
15function loggerReplacer (key: string, value: any) { 15function getLoggerReplacer () {
16 if (value instanceof Error) { 16 const seen = new WeakSet()
17 const error = {}
18 17
19 Object.getOwnPropertyNames(value).forEach(key => error[ key ] = value[ key ]) 18 // Thanks: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value#Examples
19 return (key: string, value: any) => {
20 if (typeof value === 'object' && value !== null) {
21 if (seen.has(value)) return
20 22
21 return error 23 seen.add(value)
22 } 24 }
25
26 if (value instanceof Error) {
27 const error = {}
28
29 Object.getOwnPropertyNames(value).forEach(key => error[ key ] = value[ key ])
23 30
24 return value 31 return error
32 }
33
34 return value
35 }
25} 36}
26 37
27const consoleLoggerFormat = winston.format.printf(info => { 38const consoleLoggerFormat = winston.format.printf(info => {
28 const obj = omit(info, 'label', 'timestamp', 'level', 'message') 39 const obj = omit(info, 'label', 'timestamp', 'level', 'message')
29 40
30 let additionalInfos = JSON.stringify(obj, loggerReplacer, 2) 41 let additionalInfos = JSON.stringify(obj, getLoggerReplacer(), 2)
31 42
32 if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = '' 43 if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = ''
33 else additionalInfos = ' ' + additionalInfos 44 else additionalInfos = ' ' + additionalInfos
@@ -36,7 +47,7 @@ const consoleLoggerFormat = winston.format.printf(info => {
36}) 47})
37 48
38const jsonLoggerFormat = winston.format.printf(info => { 49const jsonLoggerFormat = winston.format.printf(info => {
39 return JSON.stringify(info, loggerReplacer) 50 return JSON.stringify(info, getLoggerReplacer())
40}) 51})
41 52
42const timestampFormatter = winston.format.timestamp({ 53const timestampFormatter = winston.format.timestamp({
@@ -47,7 +58,6 @@ const labelFormatter = winston.format.label({
47}) 58})
48 59
49const fileLoggerOptions: FileTransportOptions = { 60const fileLoggerOptions: FileTransportOptions = {
50
51 filename: path.join(CONFIG.STORAGE.LOG_DIR, 'peertube.log'), 61 filename: path.join(CONFIG.STORAGE.LOG_DIR, 'peertube.log'),
52 handleExceptions: true, 62 handleExceptions: true,
53 format: winston.format.combine( 63 format: winston.format.combine(
diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts
index d32ff9b81..9731a0af9 100644
--- a/server/initializers/checker-before-init.ts
+++ b/server/initializers/checker-before-init.ts
@@ -69,13 +69,13 @@ function checkMissedConfig () {
69// Check the available codecs 69// Check the available codecs
70// We get CONFIG by param to not import it in this file (import orders) 70// We get CONFIG by param to not import it in this file (import orders)
71async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) { 71async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) {
72 if (CONFIG.TRANSCODING.ENABLED === false) return undefined
73
72 const Ffmpeg = require('fluent-ffmpeg') 74 const Ffmpeg = require('fluent-ffmpeg')
73 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs) 75 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
74 const codecs = await getAvailableCodecsPromise() 76 const codecs = await getAvailableCodecsPromise()
75 const canEncode = [ 'libx264' ] 77 const canEncode = [ 'libx264' ]
76 78
77 if (CONFIG.TRANSCODING.ENABLED === false) return undefined
78
79 for (const codec of canEncode) { 79 for (const codec of canEncode) {
80 if (codecs[codec] === undefined) { 80 if (codecs[codec] === undefined) {
81 throw new Error('Unknown codec ' + codec + ' in FFmpeg.') 81 throw new Error('Unknown codec ' + codec + ' in FFmpeg.')