Skip to content

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

🔊 — [server] Disable log coloring when TTY does not support it

Luc Didry8de04c14e976
diff --git a/server/core/helpers/logger.ts b/server/core/helpers/logger.ts
index 83aaf98fc2..07c67eff65 100644
--- a/server/core/helpers/logger.ts
+++ b/server/core/helpers/logger.ts
@@ -1,3 +1,4 @@
+import { isatty } from 'tty'
import { context, trace } from '@opentelemetry/api'
import { omit } from '@peertube/peertube-core-utils'
import { stat } from 'fs/promises'
@@ -8,6 +9,8 @@ import { FileTransportOptions } from 'winston/lib/winston/transports'
import { CONFIG } from '../initializers/config.js'
import { LOG_FILENAME } from '../initializers/constants.js'
+const isCompatibleTerminal = isatty && isatty(1) && process.env.TERM && process.env.TERM !== 'dumb'
+
const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
const consoleLoggerFormat = format.printf(info => {
@@ -58,6 +61,23 @@ if (CONFIG.LOG.ROTATION.ENABLED) {
}
function buildLogger (labelSuffix?: string) {
+ let consoleTransport = new transports.Console({
+ handleExceptions: true,
+ format: format.combine(
+ timestampFormatter,
+ format.colorize(),
+ consoleLoggerFormat
+ )
+ })
+ if (!isCompatibleTerminal) {
+ consoleTransport = new transports.Console({
+ handleExceptions: true,
+ format: format.combine(
+ timestampFormatter,
+ consoleLoggerFormat
+ )
+ })
+ }
return createLogger({
level: process.env.LOGGER_LEVEL ?? CONFIG.LOG.LEVEL,
defaultMeta: {
@@ -71,14 +91,7 @@ function buildLogger (labelSuffix?: string) {
),
transports: [
new transports.File(fileLoggerOptions),
- new transports.Console({
- handleExceptions: true,
- format: format.combine(
- timestampFormatter,
- format.colorize(),
- consoleLoggerFormat
- )
- })
+ consoleTransport
],
exitOnError: true
})