Fixed issue that logging was not actually disabled,

when no transport were configured in the production environment
This commit is contained in:
Adrian Winterstein 2024-09-28 16:23:14 +02:00
parent 4ab2d25429
commit 5e845b8aa6
No known key found for this signature in database
GPG key ID: EDBA4B9F8D8E37AE

View file

@ -19,13 +19,14 @@ const logger = winston.createLogger();
const _config = {
logger,
loggingEnabled: true, // false if no transport has been configured
loggingEnabled: false, // is set to true, if a transport gets configured
};
export { _config as _loggerConfig }; // exported for use during tests
if (IS_PROD) {
if (ENABLE_CONSOLE_LOGS_IN_PROD) {
_config.loggingEnabled = true;
logger
.add(new winston.transports.Console({ // text part
format: winston.format.combine(
@ -44,6 +45,7 @@ if (IS_PROD) {
}
if (LOGGLY_TOKEN && LOGGLY_SUBDOMAIN) {
_config.loggingEnabled = true;
logger.add(new Loggly({
inputToken: LOGGLY_TOKEN,
subdomain: LOGGLY_SUBDOMAIN,
@ -53,6 +55,7 @@ if (IS_PROD) {
}
// Do not log anything when testing unless specified
} else if (!IS_TEST || (IS_TEST && ENABLE_LOGS_IN_TEST)) {
_config.loggingEnabled = true;
logger
.add(new winston.transports.Console({
level: 'warn', // warn and errors (text part)
@ -116,8 +119,6 @@ if (IS_PROD) {
}),
),
}));
} else {
_config.loggingEnabled = false;
}
// exports a public interface insteaf of accessing directly the logger module