Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

markscott-ms
Copy link
Contributor

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:

  private static _logger: Logger | undefined;
  private static get logger(): Logger {
    if (!this._logger) {
      this._logger = initLogger(process.env.DEBUG === 'true', LoggingVisitor.name);
    }
    return this._logger;
  }

Quiet templating logs

Now that debug level logs are output in the templating parts of calm docify and calm template, we can reduce some of the logs from info level to debug level, so that calm docify only outputs the summary level logs by default.

  • 1981 lines of output with --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
  • 82 lines of output without --verbose and this PR:
    ~/architecture-as-code/calm/getting-started$ npx calm docify --architecture ./conference-signup.arch.json --output ./website 2>&1 | wc -l

Copy link
Contributor

@Copilot Copilot AI left a 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 to debug 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

Comment on lines +7 to 20

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;
Copy link
Preview

Copilot AI Aug 11, 2025

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.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant