Skip to content

Conversation

fmenezes
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@nirinchev nirinchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - I have a minor suggestion but it's not blocking.

src/logger.ts Outdated
super();
}

async initialize(): Promise<void> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than having an async instance method for initializing the logger, wouldn't it be cleaner to turn it into an async factori that calls a private constructor? That way we won't have ambiguous optionality for the logWriter.

Something like:

class DiskLogger extends LoggerBase {
  private constructor(private logWriter: MongoLogWriter) {
    super();
  }

  public static async create(logPath: string) {
    ...
    const logWriter = await manager.createLogWriter();
    return new DiskLogger(logWriter);
  }
}

@coveralls
Copy link
Collaborator

coveralls commented Apr 24, 2025

Pull Request Test Coverage Report for Build 14660881741

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 23 of 25 (92.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+6.5%) to 81.98%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/logger.ts 23 25 92.0%
Files with Coverage Reduction New Missed Lines %
src/server.ts 2 91.89%
Totals Coverage Status
Change from base Build 14639693897: 6.5%
Covered Lines: 703
Relevant Lines: 808

💛 - Coveralls

src/logger.ts Outdated
export default logger;

export async function initializeLogger(server: McpServer, logPath: string): Promise<void> {
logger.setLoggers(new McpLogger(server), new DiskLogger(logPath));
Copy link
Collaborator

@gagik gagik Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combined with Nikola's comment, I'd move the logger from global variable into this scope and return it; that way the logger variable will only exist in a valid, initalized state similar to https://github.com/mongodb-js/mongosh/blob/0ad691f4878dc52a8782ecaf66fc46928b2613f4/packages/logging/src/logging-and-telemetry.ts#L59-L67

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to do this originally, but it became a bigger change, leaving for another PR

@fmenezes fmenezes merged commit de1b5a4 into main Apr 25, 2025
8 checks passed
@fmenezes fmenezes deleted the fmenezes/refactor_log branch April 25, 2025 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants