Skip to content

Commit

Permalink
chore: default logging level to debug if debug set (#9173)
Browse files Browse the repository at this point in the history
It does not make much sense to have people explicitly set DEBUG just to
not honour it by default. This makes us set to 'debug' by default if
DEBUG Is set
  • Loading branch information
ludamad authored Oct 11, 2024
1 parent 68a7326 commit febf744
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions yarn-project/aztec/src/logging.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { onLog, setLevel } from '@aztec/foundation/log';
import { currentLevel, onLog, setLevel } from '@aztec/foundation/log';

import * as path from 'path';
import * as process from 'process';
Expand Down Expand Up @@ -55,7 +55,7 @@ function createWinstonJsonStdoutLogger(
return info;
});
return winston.createLogger({
level: process.env.LOG_LEVEL ?? 'info',
level: currentLevel,
transports: [
new winston.transports.Console({
format: format.combine(format.timestamp(), ignoreAztecPattern(), format.json()),
Expand Down
11 changes: 8 additions & 3 deletions yarn-project/foundation/src/log/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import { inspect } from 'util';
import { type LogData, type LogFn } from './log_fn.js';

const LogLevels = ['silent', 'error', 'warn', 'info', 'verbose', 'debug'] as const;
const DefaultLogLevel = process.env.NODE_ENV === 'test' ? ('silent' as const) : ('info' as const);

/**
* A valid log severity level.
*/
export type LogLevel = (typeof LogLevels)[number];

const envLogLevel = process.env.LOG_LEVEL?.toLowerCase() as LogLevel;
export let currentLevel = LogLevels.includes(envLogLevel) ? envLogLevel : DefaultLogLevel;
function getLogLevel() {
const envLogLevel = process.env.LOG_LEVEL?.toLowerCase() as LogLevel;
const defaultNonTestLogLevel = process.env.DEBUG === undefined ? ('info' as const) : ('debug' as const);
const defaultLogLevel = process.env.NODE_ENV === 'test' ? ('silent' as const) : defaultNonTestLogLevel;
return LogLevels.includes(envLogLevel) ? envLogLevel : defaultLogLevel;
}

export let currentLevel = getLogLevel();

const namespaces = process.env.DEBUG ?? 'aztec:*';
debug.enable(namespaces);
Expand Down

0 comments on commit febf744

Please sign in to comment.