Avoid circular error in logger
This commit is contained in:
parent
5d9e4eaabe
commit
959dbbd7bf
|
@ -12,22 +12,33 @@ const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
|
||||||
// FIXME: use async
|
// FIXME: use async
|
||||||
mkdirpSync(CONFIG.STORAGE.LOG_DIR)
|
mkdirpSync(CONFIG.STORAGE.LOG_DIR)
|
||||||
|
|
||||||
function loggerReplacer (key: string, value: any) {
|
function getLoggerReplacer () {
|
||||||
if (value instanceof Error) {
|
const seen = new WeakSet()
|
||||||
const error = {}
|
|
||||||
|
|
||||||
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 error
|
||||||
|
}
|
||||||
|
|
||||||
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
return value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const consoleLoggerFormat = winston.format.printf(info => {
|
const consoleLoggerFormat = winston.format.printf(info => {
|
||||||
const obj = omit(info, 'label', 'timestamp', 'level', 'message')
|
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 = ''
|
if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = ''
|
||||||
else additionalInfos = ' ' + additionalInfos
|
else additionalInfos = ' ' + additionalInfos
|
||||||
|
@ -36,7 +47,7 @@ const consoleLoggerFormat = winston.format.printf(info => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const jsonLoggerFormat = 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({
|
const timestampFormatter = winston.format.timestamp({
|
||||||
|
@ -47,7 +58,6 @@ const labelFormatter = winston.format.label({
|
||||||
})
|
})
|
||||||
|
|
||||||
const fileLoggerOptions: FileTransportOptions = {
|
const fileLoggerOptions: FileTransportOptions = {
|
||||||
|
|
||||||
filename: path.join(CONFIG.STORAGE.LOG_DIR, 'peertube.log'),
|
filename: path.join(CONFIG.STORAGE.LOG_DIR, 'peertube.log'),
|
||||||
handleExceptions: true,
|
handleExceptions: true,
|
||||||
format: winston.format.combine(
|
format: winston.format.combine(
|
||||||
|
|
|
@ -69,13 +69,13 @@ function checkMissedConfig () {
|
||||||
// Check the available codecs
|
// Check the available codecs
|
||||||
// We get CONFIG by param to not import it in this file (import orders)
|
// We get CONFIG by param to not import it in this file (import orders)
|
||||||
async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) {
|
async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) {
|
||||||
|
if (CONFIG.TRANSCODING.ENABLED === false) return undefined
|
||||||
|
|
||||||
const Ffmpeg = require('fluent-ffmpeg')
|
const Ffmpeg = require('fluent-ffmpeg')
|
||||||
const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
|
const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
|
||||||
const codecs = await getAvailableCodecsPromise()
|
const codecs = await getAvailableCodecsPromise()
|
||||||
const canEncode = [ 'libx264' ]
|
const canEncode = [ 'libx264' ]
|
||||||
|
|
||||||
if (CONFIG.TRANSCODING.ENABLED === false) return undefined
|
|
||||||
|
|
||||||
for (const codec of canEncode) {
|
for (const codec of canEncode) {
|
||||||
if (codecs[codec] === undefined) {
|
if (codecs[codec] === undefined) {
|
||||||
throw new Error('Unknown codec ' + codec + ' in FFmpeg.')
|
throw new Error('Unknown codec ' + codec + ' in FFmpeg.')
|
||||||
|
|
Loading…
Reference in New Issue