SourceHorizon / logger

Small, easy to use and extensible logger which prints beautiful logs.
https://pub.dev/packages/logger
MIT License
197 stars 33 forks source link

SimplePrinter without "TIME" #69

Closed lomby92 closed 4 months ago

lomby92 commented 4 months ago

I've tried SimplePrinter but IMO is not that simple since it adds a noisy "TIME:" string to each line. Do you think that it should be removed?

In case, i will open a PR

Bungeefan commented 4 months ago

Why would you want to remove it? If you don't like it/need it, you can disable it via the constructor parameter printTime.

lomby92 commented 4 months ago

I want the time as hours, minutes, seconds etc but I don't want to see TIME: on each log line

Bungeefan commented 4 months ago

Then I guess you have to extend the SimplePrinter and modify it to your requirements. I can't just change the output for all users.

lomby92 commented 4 months ago

Seems reasonable. I asked only because is not so common to have a generic string repeated many times in loggers.

For example: https://github.com/pinojs/pino-pretty

[17:35:28.992] INFO (42): hello world

But also in PHP and in other languages/systems.


Anyway, it's easy to create a custom Output so this is not a real problem. Thanks

lomby92 commented 4 months ago

If anyone in the future will need it:

/// Override the default SimplePrinter to customize the log output
/// without the noisy "TIME: " prefix on DateTime.
final class CustomSimplePrinter extends SimplePrinter {
  CustomSimplePrinter({printTime = false, colors = true})
      : super(printTime: printTime, colors: colors);

  @override
  List<String> log(LogEvent event) {
    List<String> logs = super.log(event);

    if (!printTime) {
      return logs;
    }

    return logs.map((l) => l.replaceAll('TIME: ', '')).toList();
  }
}