dbuenzli / logs

Logging infrastructure for OCaml
http://erratique.ch/software/logs
ISC License
86 stars 19 forks source link

Allow a CLI app to set its default log level in `Logs_cli.level` #40

Closed MisterDA closed 3 years ago

MisterDA commented 3 years ago

I'm adding support to several tools using logs and fmt of the tty, colors, and verbosity integration with cmdliner, fmt, and logs. Some of these tools were defaulting to the info error level (instead of Logs_cli default to Some Logs.Warning). It is tricky to keep that behavior with Logs_cli.level because it doesn't return whether the error level was set by the user or defaulted to Some Logs.Warning. The suggested workaround to use env seem to indicate that I could set that parameter, test the existence of the env var, do a putenv if it isn't set, and then call Logs_cli.level. Maybe I've missed something, but an easy and nice way is to add an optional default parameter (that still defaults to Some Logs.Warning) to Logs_cli.level. Using Logs.level_to_string default also allows the help page to report the app chosen default level.

dbuenzli commented 3 years ago

As per level semantics, the info level is for getting more information about how the program operates. It's not meant to be output by default. This PR would also break the convention established by this cli interface that adding -v increases verbosity, and that it does so in two steps, info and debug.

The more programs behave the same way, the better.

If you think it's justified for you to walk away from that convention, just define your own option.

MisterDA commented 3 years ago

Fair enough, thanks for the explanation.