Skip to content

Commit 51038fa

Browse files
author
Vianney Gremmel
committed
Add logger parameters antipattern
1 parent b4b7c23 commit 51038fa

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Not letting logger format messages
2+
----------------------------------
3+
4+
When you log a message, do not format your message with parameters. You should
5+
let logger lib handle that.
6+
7+
8+
Anti-pattern
9+
------------
10+
11+
.. code:: python
12+
msg = "Error %s catched!"
13+
logger.error(msg % 1337)
14+
15+
16+
Best practice(s)
17+
----------------
18+
19+
Let logger format message
20+
.........................
21+
22+
Pass message parameters as arguments to the logger function.
23+
24+
.. code:: python
25+
msg = "Error %s catched!"
26+
logger.error(msg, 1337)
27+
28+
29+
References
30+
----------
31+
- `Python logging howto <https://docs.python.org/3/howto/logging.html#logging-variable-data>`_

0 commit comments

Comments
 (0)