You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.rst
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,8 @@
16
16
- Make ``logger.catch()`` usable as an asynchronous context manager (`#1084 <https://github.com/Delgan/loguru/issues/1084>`_).
17
17
- Make ``logger.catch()`` compatible with asynchronous generators (`#1302 <https://github.com/Delgan/loguru/issues/1302>`_).
18
18
- Improve feedback for invalid format keys in logger format strings (`#1450 <https://github.com/Delgan/loguru/issues/1450>`_, thanks `@Krishnachaitanyakc <https://github.com/Krishnachaitanyakc>`_).
19
+
- Support python-3.14 template strings as log messages. The comfort of f-string syntax combined with the performance of lazily evaluated formatting. (`#1397 <https://github.com/Delgan/loguru/issues/1302>`_).
**Loguru** is a library which aims to bring enjoyable logging in Python.
26
26
@@ -109,10 +109,24 @@ logger.add("file_Y.log", compression="zip") # Save some loved space
109
109
110
110
### Modern string formatting using braces style
111
111
112
-
Loguru favors the much more elegant and powerful `{}` formatting over `%`, logging functions are actually equivalent to `str.format()`.
112
+
For python-3.14 and higher, you can pass a template string, which will be evaluated lazily. The behavior is the same as with a f-string, but the performance is better: Messages that are never emitted won't pay the cost of evaluation.
113
113
114
114
```python
115
-
logger.info("If you're using Python {}, prefer {feature} of course!", 3.6, feature="f-strings")
115
+
version =3.14
116
+
feature ="t-strings"
117
+
logger.info(t"If you're using Python {version}, prefer {feature} of course!")
118
+
```
119
+
120
+
Before python-3.14, you can still use lazily evaluated formatting and the elegant and powerful `{}` formatting: Use a str.format() style string and pass the parameters as additional arguments:
121
+
122
+
```python
123
+
logger.info("If you're using Python {}, prefer {feature} of course!", 3.6, feature="str.format() style strings")
124
+
```
125
+
126
+
Note that using f-strings in log messages is not considered best practice for performance reasons, as they are evaluated eagerly. Expensive conversion to string might occur even when in the end they are not needed:
127
+
128
+
```python
129
+
logger.debug(f"obj = {large_obj}") # Do not do this, prefer the above methods!
0 commit comments