Choose level for std logger
I have some loggers configured using the
setup
function from std/log
. This way levels are hard-coded. I would like to be able to pass a --debug
option to my script to activate the DEBUG level, otherwise use INFO and above.
Is it possible to achieve this using std/log? If not, what are other libs you can recommend instead?9 Replies
Detect the CLI flag and set the appropriate log level on the
Logger
instance (or your custom once). Only log levels equal to the one on the Logger
instance or higher are loggedThere a function
getLogger
which return logger instance. It only accepts name
as a parameter, no way to pass level there.
The level doesn’t seem to have a setter, so this code won’t work:
Ah okay levelName
seems to workSounds like you've got a working solution. I've written an alternative logging framework which can do this through the use of environment variables or command line options. https://github.com/onjara/optic
Much better than std's logger IMO
Perhaps a pr to upgrade std before std 1.0 ?
Thanks!
That's kind of you, however, my logger isn't really a good fit for std I think. For starters the fluent interface would be out of place there.
Just a thought. Love your work!
Nice! One thing I’m missing in std logger is the trace level
Suggestions for features for
std/log
are more than welcome! If you guys have any, feel free to open a GitHub issue.