simc / logger

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

Enhancement to allow control over 'boxing' of PrettyPrinter() by logging Level #89

Open timmaffett opened 3 years ago

timmaffett commented 3 years ago

I have made a simple enhancement to PrettyPrinter() to allow simple control of boxing of log messages by level.
I have done this via optional constructor parameters to allow this optionally while allowing ease of use by users.
I will make a new PR once you have processed my current (very trivial) PR which prevents color bleed of stack traces to the subsequent line (It is possible that was the intended behavior, in which case I will remove that 'fix').(Oops I see that I pushed this enhancement already so it is there in second/third commit in my PR)

A simple overview of using PrettyPrinter() with the new changes:

Create a PrettyPrinter and prevent boxing at Level.verbose and Level.info levels:

var logger = Logger(
  printer: PrettyPrinter( excludeBox:{ Level.verbose:true, Level.info:true } ),
}

Create one to prevent boxing at all levels:

  printer: PrettyPrinter( noBoxingByDefault:true ),

Create one to box only at Level.error (using both parameters for the least code to accomplish this)

  printer: PrettyPrinter( noBoxingByDefault:true, excludeBox:{ Level.error:false } ),

You get the idea :) The changes are very simple and I believe this flexibility will make Logger even more versatile and attractive to many users. I am of course open to any changes or suggestions you have. (I also have a LogOutput class/plugin which outputs to FireBase/FireStore, but I need to clean that up and generalize it)

Thanks for the versatile and useful logger!