Closed petedmarsh closed 10 months ago
How does this compare to f
strings?
f-strings would also be eagerly evaluated, to have lazy interpolation of the log messages the best way is to use %-style formatting and pass the arguments to the logger methods
@liampauling I've formatted the code
thanks, test failing
@liampauling I've fixed the test, sorry!
Logging like this:
causes the message string to always be interpolated even if the message is not going to be logged.
Logging like this:
will mean the string is only ever interpolated if it will be logged.
In practice here this will make little difference if the log level is INFO or above, but it does mean a
if
statement can be removed from StreamListener.See:
https://docs.python.org/3/howto/logging.html#optimization https://stackoverflow.com/questions/4148790/lazy-logger-message-string-evaluation