sapristi / easy_logging

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

Change logger level dinamically #2

Closed vincenzopalazzo closed 3 years ago

vincenzopalazzo commented 3 years ago

Maybe this problem was covered from this issue https://github.com/sapristi/easy_logging/issues/1 and maybe it only my limit with OCaml.

I'm using this in the library in one of my projects with Ocaml and I'm searching the possibility to change the log level dinamically without change the code.

In other words, I have my application statically logger and I want to introduce the feature to run it with a flag --debug and has the level changed inside the logger.

It is possible to have this feature with the library, if yes can suggest me an example to reproduce it inside my application?

Thanks.

sapristi commented 3 years ago

Hello, yes it is totally possible to change the log level dynamically. You can see a real-life example here: https://github.com/sapristi/alife/blob/dev/src/bin/yaacs_server.ml

There is also a generic example here: https://github.com/sapristi/alife/blob/dev/src/gui/server/logs_server.ml (where logs level are set by web requests).

Basically, all you have to do is retrieve the logger you want to set with Logging.get_logger and then use the set_level method:

let logger = logging.get_logger "my.logger" in
logger#set_level "debug"
vincenzopalazzo commented 3 years ago

Oh, thanks so much :) and sorry for the stupid question