1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

Add ability to configure log level

This commit is contained in:
Chocobozzz 2018-01-19 13:58:13 +01:00
parent c7a9f34f72
commit 23e27dd535
No known key found for this signature in database
GPG key ID: 583A612D890159BE
13 changed files with 183 additions and 67 deletions

View file

@ -9,26 +9,57 @@ const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
// Create the directory if it does not exist
mkdirp.sync(CONFIG.STORAGE.LOG_DIR)
const logger = new winston.Logger({
// Use object for better performances (~ O(1))
const excludedKeys = {
level: true,
message: true,
splat: true,
timestamp: true,
label: true
}
function keysExcluder (key, value) {
return excludedKeys[key] === true ? undefined : value
}
const loggerFormat = winston.format.printf((info) => {
let additionalInfos = JSON.stringify(info, keysExcluder, 2)
if (additionalInfos === '{}') additionalInfos = ''
return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message} ${additionalInfos}`
})
const timestampFormatter = winston.format.timestamp({
format: 'YYYY-MM-dd HH:mm:ss.SSS'
})
const labelFormatter = winston.format.label({
label
})
const logger = new winston.createLogger({
level: CONFIG.LOG.LEVEL,
transports: [
new winston.transports.File({
level: 'debug',
filename: path.join(CONFIG.STORAGE.LOG_DIR, 'all-logs.log'),
filename: path.join(CONFIG.STORAGE.LOG_DIR, 'peertube.log'),
handleExceptions: true,
json: true,
maxsize: 5242880,
maxFiles: 5,
colorize: false,
prettyPrint: true
format: winston.format.combine(
timestampFormatter,
labelFormatter,
winston.format.splat(),
winston.format.json()
)
}),
new winston.transports.Console({
level: 'debug',
label: label,
handleExceptions: true,
humanReadableUnhandledException: true,
json: false,
colorize: true,
prettyPrint: true
format: winston.format.combine(
timestampFormatter,
winston.format.splat(),
labelFormatter,
winston.format.colorize(),
loggerFormat
)
})
],
exitOnError: true
@ -36,4 +67,9 @@ const logger = new winston.Logger({
// ---------------------------------------------------------------------------
export { logger }
export {
timestampFormatter,
labelFormatter,
loggerFormat,
logger
}