Skip to content
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

Add CopyWith to LogRecord #485

Open
SharbelOkzan opened this issue Oct 7, 2024 · 0 comments
Open

Add CopyWith to LogRecord #485

SharbelOkzan opened this issue Oct 7, 2024 · 0 comments

Comments

@SharbelOkzan
Copy link

Consider the following use-case

Logger.root.onRecord.listen(logToCosole);
Logger.root.onRecord.listen(CrashAnlyticsTool.listenToLogs);

Where:
logToConsole is my custom function that logs to the debug console.
CrashAnlyticsTool is an external library, compatible with the logging package and provides a method listenToLogs via an extension. (a real example can be sentry_logging.

Now say that I decided to add a warning emoji (⚠️) to the logs of level SEVER. I can modify logToConsole to add the emoji on the fly before dumping to the console. However, I'm not able to modify the external method CrashAnlyticsTool.listenToLogs.
Using stream.map is one good solution. The problem is that LogRecord is immutable, doesn't have copyWith method, and doesn't have a constructor that exposes all fields.

The proposed change is either:

  1. Adding a copyWith method
  2. Adding a named constructor that accepts time and sequenceNumber as params.

Then the solution for the above will look somthing like

  LogRecord converter(LogRecord event) {
    return event.copyWith(message: "⚠️" + event.message);
  }
  Logger.root.onRecord.map(converter);
  Logger.root.onRecord.listen(logToCosole);
  Logger.root.onRecord.listen(CrashAnlyticsTool.listenToLogs);
@mosuem mosuem transferred this issue from dart-archive/logging Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants