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

Refactor plugin helpers factory

This commit is contained in:
Chocobozzz 2020-04-09 09:57:32 +02:00
parent 00c228363f
commit bc0d801bb7
No known key found for this signature in database
GPG key ID: 583A612D890159BE
5 changed files with 242 additions and 169 deletions

View file

@ -54,9 +54,11 @@ const jsonLoggerFormat = winston.format.printf(info => {
const timestampFormatter = winston.format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss.SSS'
})
const labelFormatter = winston.format.label({
label
})
const labelFormatter = (suffix?: string) => {
return winston.format.label({
label: suffix ? `${label} ${suffix}` : label
})
}
const fileLoggerOptions: FileTransportOptions = {
filename: path.join(CONFIG.STORAGE.LOG_DIR, LOG_FILENAME),
@ -72,25 +74,29 @@ if (CONFIG.LOG.ROTATION.ENABLED) {
fileLoggerOptions.maxFiles = CONFIG.LOG.ROTATION.MAX_FILES
}
const logger = winston.createLogger({
level: CONFIG.LOG.LEVEL,
format: winston.format.combine(
labelFormatter,
winston.format.splat()
),
transports: [
new winston.transports.File(fileLoggerOptions),
new winston.transports.Console({
handleExceptions: true,
format: winston.format.combine(
timestampFormatter,
winston.format.colorize(),
consoleLoggerFormat
)
})
],
exitOnError: true
})
const logger = buildLogger()
function buildLogger (labelSuffix?: string) {
return winston.createLogger({
level: CONFIG.LOG.LEVEL,
format: winston.format.combine(
labelFormatter(labelSuffix),
winston.format.splat()
),
transports: [
new winston.transports.File(fileLoggerOptions),
new winston.transports.Console({
handleExceptions: true,
format: winston.format.combine(
timestampFormatter,
winston.format.colorize(),
consoleLoggerFormat
)
})
],
exitOnError: true
})
}
function bunyanLogFactory (level: string) {
return function () {
@ -123,6 +129,7 @@ const bunyanLogger = {
// ---------------------------------------------------------------------------
export {
buildLogger,
timestampFormatter,
labelFormatter,
consoleLoggerFormat,