4 ms·
There already is a syntax for writing log messages where the arguments are only evaluated when they are needed. logger.debug("bla: %s" % myvar).
by zelphirkalt 2y ago
There already is a syntax for writing log messages where the arguments are only evaluated when they are needed. logger.debug("bla: %s" % myvar).
- Hasnep 2y agoActually, the % syntax eagerly evaluates the log string, you need to pass the variables as arguments to the logging function like this: logger.debug("bla: %s", myvar). It's such a subtle difference that I only notice it when my IDE underlines it :/
- zelphirkalt 2y agoYou are right! I mixed them up as well. Here is a good source: https://blog.pilosus.org/posts/2020/01/24/python-f-strings-in-logging/ https://blog.pilosus.org/posts/2020/01/24/python-f-strings-i... (not mine)