[logging] log level specified in env `LOG_LEVEL` variable
-
Maintainer
@AlfredoDiNapoli What do you think of this commit? It's a simple way to specify log level by setting
LOG_LEVEL=DEBUG
in environment. One can then specify log level for tests etc to remove the debug messages. -
Maintainer
@cgenie Yes, in principle I'm happy with this for now. Some things to think about for the near/medium term:
-
How do we document all these env vars? We have quite a few within garg (for example I use one in test to enable verbose logging of HTTP requests), but they are quite easy to miss and forget about. Maybe we could have an enum type which would map to env var names, and have a way to turn that into documentation in the
README
, or similar. -
What you have done here works for the IO Logger, which is really the "worst" logger we could use as I have added it just as an escape hatch to be able to log in every
IO
monad. Ideally we should have a general (i.e. abstracted) machinery so that this behaviour becomes standard in all the instances ofHasLogger m
wherem
is eitherMonadIO m
orMonadBaseControl IO m
or similar. This way we don't have to repeat this boilerplate every time. -
The implementation of
logMsg
forIO
is doing something that in principle should be abstracted out for every logger. In fact, I remember (but I can't easily check the code now) that there is already some piece of machinery in theMonadLogger
class that does what you are doing here. Again, we should abstract this out, because the level filtering is something general to all loggers, not justIO
.
-