It depends on the situation. There are cases when I "expect the exception" - for example anything that touches the network has a tiny chance of failing. I want to know how often this happen, because too many network errors probably means that something is down and needs to be investigated (and we have alerts for this, based on logs). But to be fair I usually just log .exception() in this case anyway (even if I know exactly what the exception will be).
Oh no, I would not necessarily log an exception, the same way I don’t log every time an ”else” clause is reached. But in the places I do want to log.error("something") in an exception handler, I don’t want some linter complaining that since there is an active exception, it thinks I ought to have used log.exception().
Re:Flake8-Logging
by globular-toast on Tuesday September 12, 2023 @05:07AM
(#37478470)
Depends what you're logging. An info level log is quite explicitly for an expected path, e.g. "config not found, using defaults".
This rule is only for error calls, though. In that case, yeah, you wouldn't log an error for an expected path.
If it’s expected, I tend not to log it.