Skip to content

Commit 3f70782

Browse files
matusvaloPierre-SassoulasDanielNoord
authored
Added logging-not-lazy message example (#6619)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com> Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
1 parent 0007c32 commit 3f70782

4 files changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import logging
2+
3+
try:
4+
function()
5+
except Exception as e:
6+
logging.error('Error occured: %s' % e) # [logging-not-lazy]
7+
raise
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Another reasonable option is to use f-strings. If you want to do that, you need to enable
2+
``logging-not-lazy`` and disable ``logging-fstring-interpolation``.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import logging
2+
3+
try:
4+
function()
5+
except Exception as e:
6+
logging.error('Error occured: %s', e)
7+
raise
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `Logging variable data <https://docs.python.org/3/howto/logging.html#logging-variable-data>`_
2+
- `Rationale <https://stackoverflow.com/questions/34619790>`_

0 commit comments

Comments
 (0)