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

Encoding issue #60

Closed busslina closed 7 months ago

busslina commented 7 months ago

This case is on web (console) but I think it happens in sever (file).

log.t('Websocket connection -- On done (Stream) -- $id');

Prints in web console this:

�[38;5;244m[T]�[0m  Websocket connection -- On done (Stream) -- [NOT SET YET]

It is weird because it is printing okay this:

[D]  Connecting to Webosckets Server

My logger is:

Logger(
      level: use(appCapsule).logLevel.casted,  // trace
      filter: ProductionFilter(),
      output: ConsoleOutput(),
      printer: SimplePrinter(),
    )
busslina commented 7 months ago

It is due to logger using ANSI color codes when using ConsoleOutput, so maybe this lib have to check if it is a web console and not use colored strings

Bungeefan commented 7 months ago

Hi, yeah, it seems that the browser consoles do not support the ANSI color codes. Fortunately, this can be easily solved by adding colors: false to the constructor of the respective printer.

Nevertheless, I am not really a fan of making the default behavior platform dependent. If the user doesn't want colors, it is easy to configure in the constructor, heck if it is desired, even the user can make it platform dependent for their project in one single line ;)

printer: PrettyPrinter(
  colors: !const bool.fromEnvironment('dart.library.js_util'),
),
busslina commented 7 months ago

@Bungeefan Thank you, I didn't knew that option