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
Notably:
- Fix support for t-strings with `opt(colors=True)`
- Handle nested t-strings properly
- Implement formatting of t-string in tracebacks (new tokens)
- Update the type hints stub to accept t-strings
- Mention t-strings in documentation
- Add many more unit tests in dedicated file
Copy file name to clipboardExpand all lines: CHANGELOG.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@
3
3
4
4
- Change the default log format to include the timezone offset since it produces less ambiguous logs (`#856 <https://github.com/Delgan/loguru/pull/856>`_, thanks `@tim-x-y-z <https://github.com/tim-x-y-z>`_).
5
5
- Add new ``logger.reinstall()`` method to automatically set up the ``logger`` in spawned child processes (`#818 <https://github.com/Delgan/loguru/issues/818>`_, thanks `@monchin <https://github.com/monchin>`_).
6
+
- Add support for template strings used as log messages (`#1397 <https://github.com/Delgan/loguru/issues/1397>`_, thanks `@TurtleOrangina <https://github.com/TurtleOrangina>`_).
6
7
- Fix incorrect microsecond value when formatting the log timestamp using ``{time:x}`` (`#1440 <https://github.com/Delgan/loguru/issues/1440>`_).
7
8
- Fix hex color short code expansion (`#1426 <https://github.com/Delgan/loguru/issues/1426>`_, thanks `@turkoid <https://github.com/turkoid>`_).
8
9
- Fix possible internal error when dealing with (rare) frame objects missing a ``f_lineno`` value (`#1435 <https://github.com/Delgan/loguru/issues/1435>`_).
@@ -17,7 +18,6 @@
17
18
- Make ``logger.catch()`` usable as an asynchronous context manager (`#1084 <https://github.com/Delgan/loguru/issues/1084>`_).
18
19
- Make ``logger.catch()`` compatible with asynchronous generators (`#1302 <https://github.com/Delgan/loguru/issues/1302>`_).
19
20
- Improve feedback for invalid format keys in logger format strings (`#1450 <https://github.com/Delgan/loguru/issues/1450>`_, thanks `@Krishnachaitanyakc <https://github.com/Krishnachaitanyakc>`_).
20
-
- 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,24 +109,17 @@ logger.add("file_Y.log", compression="zip") # Save some loved space
109
109
110
110
### Modern string formatting using braces style
111
111
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.
112
+
Loguru favors the much more elegant and powerful `{}` formatting over `%`, logging functions are actually equivalent to `str.format()`.
113
113
114
114
```python
115
-
version =3.14
116
-
feature ="t-strings"
117
-
logger.info(t"If you're using Python {version}, prefer {feature} of course!")
115
+
logger.info("If handler level exceeds {}, formatting is {action}", 20, action="skipped")
118
116
```
119
117
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:
118
+
For python-3.14 and higher, you can pass [a template string](https://peps.python.org/pep-0750/), which will be evaluated lazily and is preferable over f-strings:
121
119
122
120
```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!
121
+
feature ="t-string"
122
+
logger.info(t"Modern Pythonistas can enjoy {feature}!")
0 commit comments