-
Notifications
You must be signed in to change notification settings - Fork 58
Fix initialization of loggers that check process.env.DEBUG
; quiet templating logs
#1517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes delayed logger initialization to ensure the --verbose
CLI option works correctly, and reduces log noise by changing templating logs from info to debug level. The core issue was that loggers were initialized too early (before CLI parsing) when checking process.env.DEBUG
.
Key changes:
- Converted static logger initialization to lazy getters across multiple classes
- Changed templating log levels from
info
todebug
to reduce output noise - Updated corresponding test expectations to match the new debug logging behavior
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
shared/src/template/template-processor.ts | Converted static logger to lazy getter pattern |
shared/src/template/template-path-extractor.ts | Applied lazy logger initialization and changed info logs to debug |
shared/src/template/template-engine.ts | Applied lazy logger initialization and changed template preprocessing log to debug |
shared/src/template/template-engine.spec.ts | Updated test to expect debug logging instead of info |
shared/src/template/template-bundle-file-loader.ts | Applied lazy logger initialization pattern |
shared/src/resolver/calm-reference-resolver.ts | Applied lazy logger initialization to all resolver classes |
shared/src/model-visitor/logging-visitor.ts | Applied lazy logger initialization with additional setter for testing |
|
||
private static get logger(): Logger { | ||
if (!this._logger) { | ||
this._logger = initLogger(process.env.DEBUG === 'true', LoggingVisitor.name); | ||
} | ||
return this._logger; | ||
} | ||
// Setter for testing purposes | ||
private static set logger(value: Logger) { | ||
this._logger = value; | ||
} | ||
|
||
async visit(obj: unknown, path: string[] = []): Promise<void> { | ||
const logger = LoggingVisitor.logger; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setter for testing purposes breaks the lazy initialization pattern and could lead to inconsistent behavior. Consider using dependency injection or a factory pattern instead of exposing a setter that bypasses the lazy initialization logic.
private static get logger(): Logger { | |
if (!this._logger) { | |
this._logger = initLogger(process.env.DEBUG === 'true', LoggingVisitor.name); | |
} | |
return this._logger; | |
} | |
// Setter for testing purposes | |
private static set logger(value: Logger) { | |
this._logger = value; | |
} | |
async visit(obj: unknown, path: string[] = []): Promise<void> { | |
const logger = LoggingVisitor.logger; | |
private readonly _loggerInstance?: Logger; | |
constructor(logger?: Logger) { | |
this._loggerInstance = logger; | |
} | |
private static get logger(): Logger { | |
if (!this._logger) { | |
this._logger = initLogger(process.env.DEBUG === 'true', LoggingVisitor.name); | |
} | |
return this._logger; | |
} | |
async visit(obj: unknown, path: string[] = []): Promise<void> { | |
const logger = this._loggerInstance ?? LoggingVisitor.logger; |
Copilot uses AI. Check for mistakes.
Delayed(lazy) logger initialization
Loggers that were defined as:
private static logger = initLogger(process.env.DEBUG === true, ...)
were initialized too early, before the CLI parsed the command line options. This meant that the
--verbose
option did not work.This has been changed to a lazy initialisation:
Quiet templating logs
Now that debug level logs are output in the templating parts of
calm docify
andcalm template
, we can reduce some of the logs frominfo
level todebug
level, so thatcalm docify
only outputs the summary level logs by default.--verbose
or before this PR:~/architecture-as-code/calm/getting-started$ npx calm docify --architecture ./conference-signup.arch.json --output ./website --verbose 2>&1 | wc -l
--verbose
and this PR:~/architecture-as-code/calm/getting-started$ npx calm docify --architecture ./conference-signup.arch.json --output ./website 2>&1 | wc -l