sapristi / easy_logging

Logging module for OCaml
Mozilla Public License 2.0
10 stars 0 forks source link

Make log levels easier to access #1

Closed cemerick closed 3 years ago

cemerick commented 5 years ago

As the types are currently defined, one needs to explicitly reach into Easy_logging__.Easy_logging_types to use log levels outside of e.g. a Logging.make_logger call.

This makes configuring loggers from some configuration more verbose than it could be, i.e. the following won't compile:

open Easy_logging
let cache_log_level = try ignore @@ Unix.getenv "CACHE_LOG"; Debug
                      with Not_found -> NoLevel
sapristi commented 5 years ago

Hello @cemerick , thanks for the feedback ! I have implemented a fix, log_level values should now be available directly from Easy_logging.

It should be on opam soon enough, but if you dont want to wait you can install via git clone then opam install easy_logging.opam from within the cloned directory.

sapristi commented 5 years ago

Ok there was some problems with the fix, because the Error constructor from stdlib was hidden by the Error log_level. I have instead made the type available in the Logging module, so that no collision should happen.

You should now be able to write:

open Easy_logging
let cache_log_level = try ignore @@ Unix.getenv "CACHE_LOG"; Logging.Debug
                      with Not_found -> Logging.NoLevel 
cemerick commented 5 years ago

That looks perfectly reasonable, thanks! The trailing underscores on the "types" module just screamed "internal, don't use!" :smile:

cemerick commented 5 years ago

Friendly reminder: it looks like you forgot to submit a new release PR to opam? I see the retracted https://github.com/ocaml/opam-repository/pull/14576 (presumably including the first cut of the change that shadowed Error), but otherwise the available version remains at 0.5.

sapristi commented 5 years ago

Ok version 0.5.2 is being published to Opam (https://github.com/ocaml/opam-repository/pull/14643). I just added some methods to have better control over a logger's handlers.