Closed
Description
Apologies if this is something that's been dealt with before but I couldn't find it in past issues or PRs.
If I set up a leveled logger and do some leveled log statements e.g.:
logger := levels.New(log.NewJSONFormatter(os.Stdout))
logger.Debug().Log("msg", "some debug stuff")
logger.Error().Log("err", "got an error")
logger.Info().Log("action", "user action was taken")
I would want the ability to set a log level above which I receive the log statements but below which they're discarded. Something like:
logger.LogLevel(levels.Error)
logger.Debug().Log("msg", "more debug stuff") // now doesn't log anything
This saves a bit of CPU and I/O cost. It's a feature that log15 had, seems it just never came over here.
Also, you could prevent the evaluation of Valuer
s, so I can do:
logger.Debug().Log("wowza", func() inferface{} { return someExpensiveOp() })
...but if the log level is set to Info or above, not only does this line not get evaluated, someExpensiveOp
never gets called.
I'm game to do the work and send the PR if this sounds like something desirable!