Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Don't use file logger in worker threads

Chocobozzzfd2292c72305
diff --git a/server/core/helpers/logger.ts b/server/core/helpers/logger.ts
index 4e10d7c1b5..73a60923ff 100644
--- a/server/core/helpers/logger.ts
+++ b/server/core/helpers/logger.ts
@@ -5,10 +5,11 @@ import { stat } from 'fs/promises'
import { join } from 'path'
import { format as sqlFormat } from 'sql-formatter'
import { isatty } from 'tty'
-import { createLogger, format, transports } from 'winston'
+import { createLogger, format, transport, transports } from 'winston'
+import { FileTransportOptions } from 'winston/lib/winston/transports/index.js'
+import { isMainThread } from 'worker_threads'
import { CONFIG } from '../initializers/config.js'
import { LOG_FILENAME } from '../initializers/constants.js'
-import { FileTransportOptions } from 'winston/lib/winston/transports/index.js'
const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
@@ -77,6 +78,16 @@ export function buildLogger (options: {
fileLoggerOptions.maxFiles = CONFIG.LOG.ROTATION.MAX_FILES
}
+ const loggerTransports: transport[] = []
+
+ // Don't add file logger transport in worker threads in production
+ // See https://github.com/winstonjs/winston/issues/2393
+ if (isMainThread || isTestOrDevInstance()) {
+ loggerTransports.push(new transports.File(fileLoggerOptions))
+ }
+
+ loggerTransports.push(consoleTransport)
+
return createLogger({
level: process.env.LOGGER_LEVEL ?? CONFIG.LOG.LEVEL,
defaultMeta: {
@@ -94,10 +105,7 @@ export function buildLogger (options: {
labelFormatter(labelSuffix),
format.splat()
),
- transports: [
- new transports.File(fileLoggerOptions),
- consoleTransport
- ],
+ transports: loggerTransports,
exitOnError: true
})
}
@@ -218,6 +226,7 @@ function getAdditionalInfo (info: any) {
}
function doesConsoleSupportColor () {
- return isTestOrDevInstance() ||
- (isatty(1) && process.env.TERM && process.env.TERM !== 'dumb')
+ if (isTestOrDevInstance()) return true
+
+ return isatty(1) && process.env.TERM && process.env.TERM !== 'dumb'
}
diff --git a/server/core/helpers/threads.ts b/server/core/helpers/threads.ts
index 15d9741711..ff6b85a26f 100644
--- a/server/core/helpers/threads.ts
+++ b/server/core/helpers/threads.ts
@@ -1,3 +1,4 @@
+import { isTestOrDevInstance } from '@peertube/peertube-node-utils'
import { isMainThread } from 'node:worker_threads'
import { logger } from './logger.js'
@@ -5,4 +6,6 @@ export function assertIsInWorkerThread () {
if (!isMainThread) return
logger.error('Caller is not in worker thread', { stack: new Error().stack })
+
+ if (isTestOrDevInstance()) process.exit(1)
}