-const logger = winston.createLogger({
- level: CONFIG.LOG.LEVEL,
- format: winston.format.combine(
- labelFormatter,
- winston.format.splat()
- ),
- transports: [
- new winston.transports.File({
- filename: path.join(CONFIG.STORAGE.LOG_DIR, 'peertube.log'),
- handleExceptions: true,
- maxsize: 1024 * 1024 * 12,
- maxFiles: 20,
- format: winston.format.combine(
- winston.format.timestamp(),
- jsonLoggerFormat
- )
- }),
- new winston.transports.Console({
- handleExceptions: true,
- format: winston.format.combine(
- timestampFormatter,
- winston.format.colorize(),
- consoleLoggerFormat
- )
- })
- ],
- exitOnError: true
-})
+const fileLoggerOptions: FileTransportOptions = {
+ filename: join(CONFIG.STORAGE.LOG_DIR, LOG_FILENAME),
+ handleExceptions: true,
+ format: format.combine(
+ format.timestamp(),
+ jsonLoggerFormat
+ )
+}
+
+if (CONFIG.LOG.ROTATION.ENABLED) {
+ fileLoggerOptions.maxsize = CONFIG.LOG.ROTATION.MAX_FILE_SIZE
+ fileLoggerOptions.maxFiles = CONFIG.LOG.ROTATION.MAX_FILES
+}
+
+function buildLogger (labelSuffix?: string) {
+ return createLogger({
+ level: CONFIG.LOG.LEVEL,
+ defaultMeta: {
+ get traceId () { return getSpanContext(context.active())?.traceId },
+ get spanId () { return getSpanContext(context.active())?.spanId },
+ get traceFlags () { return getSpanContext(context.active())?.traceFlags }
+ },
+ format: format.combine(
+ labelFormatter(labelSuffix),
+ format.splat()
+ ),
+ transports: [
+ new transports.File(fileLoggerOptions),
+ new transports.Console({
+ handleExceptions: true,
+ format: format.combine(
+ timestampFormatter,
+ format.colorize(),
+ consoleLoggerFormat
+ )
+ })
+ ],
+ exitOnError: true
+ })
+}
+
+const logger = buildLogger()
+
+// ---------------------------------------------------------------------------