Skip to content

Conversation

@jfsanchez91
Copy link
Contributor

@jfsanchez91 jfsanchez91 commented Sep 21, 2025

Replace print statements with a lightweight logging implementation.

Here is a simple example how users can customize it and how to iterop with Dart package:logging too

// user package:logging config
hierarchicalLoggingEnabled = true;
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
  final time = record.time.toIso8601String();
  final level = record.level.name.padRight(7);
  final loggerName = record.loggerName;
  final message = record.message;
  final error = record.error != null ? ' Error: ${record.error}' : '';
  final stack = record.stackTrace != null ? '\n${record.stackTrace}' : '';

  print('$time [$level] $loggerName: $message$error$stack');
});

// interop with package:logging
mcp_dart.Logger.setHandler((name, level, message) {
  final mappedLevel = switch (level) {
    mcp_dart.LogLevel.debug => Level.FINE,
    mcp_dart.LogLevel.info => Level.INFO,
    mcp_dart.LogLevel.warn => Level.WARNING,
    mcp_dart.LogLevel.error => Level.SEVERE,
  };
  Logger(name).log(mappedLevel, message);
});
Logger('mcp_dart').level = Level.INFO;
image

@codecov
Copy link

codecov bot commented Sep 21, 2025

Codecov Report

❌ Patch coverage is 32.71028% with 72 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.98%. Comparing base (1f08bd5) to head (95c45be).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
lib/src/client/stdio.dart 30.76% 18 Missing ⚠️
lib/src/server/sse_server_manager.dart 0.00% 10 Missing ⚠️
lib/src/server/stdio.dart 0.00% 9 Missing ⚠️
lib/src/server/server.dart 0.00% 7 Missing ⚠️
lib/src/server/mcp.dart 0.00% 6 Missing ⚠️
lib/src/server/sse.dart 25.00% 6 Missing ⚠️
lib/src/shared/iostream.dart 53.84% 6 Missing ⚠️
lib/src/client/client.dart 55.55% 4 Missing ⚠️
lib/src/shared/protocol.dart 0.00% 3 Missing ⚠️
lib/src/shared/stdio.dart 40.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #41      +/-   ##
==========================================
+ Coverage   45.55%   45.98%   +0.43%     
==========================================
  Files          15       16       +1     
  Lines        2880     2903      +23     
==========================================
+ Hits         1312     1335      +23     
  Misses       1568     1568              
Flag Coverage Δ
unittests 45.98% <32.71%> (+0.43%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leehack
Copy link
Owner

leehack commented Sep 22, 2025

@jfsanchez91 Thanks for the PR, but I'm hesitant to add a dependency for logging since I want to make the library as light as possible. Would you mind rewriting a lightweight logger instead of using an external lib?

@jfsanchez91 jfsanchez91 marked this pull request as draft September 22, 2025 15:15
@jfsanchez91 jfsanchez91 force-pushed the feature/raplace-print-with-logging branch from d5cd18c to 0e87f0e Compare September 22, 2025 15:22
@jfsanchez91 jfsanchez91 changed the title Replace print statements with logging library for configurable logs Replace print statements with lightweight logging implementation Sep 22, 2025
@jfsanchez91 jfsanchez91 marked this pull request as ready for review September 22, 2025 15:39
@jfsanchez91
Copy link
Contributor Author

@leehack done, now it provides a lightweight logging impl, that can also interop with package:logging if needed

@jfsanchez91 jfsanchez91 force-pushed the feature/raplace-print-with-logging branch from 0e87f0e to 66e5e53 Compare September 22, 2025 15:45
@leehack leehack merged commit 27cda66 into leehack:main Oct 9, 2025
2 of 3 checks passed
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.

2 participants