tstring-logger
Python logging with template strings with support for conditional (lazy) execution of functions in log messages.
Provides TStringLogger(logging.Logger) and sets it as the default logger class upon import tstring_logger
A Template String may embed function calls with a !fn format specifier. They will only be executed if the logger is active.
Example
import logging
import tstring_logger
def expensive_function(x):
time.sleep(1)
return 2 * x
logging.basicConfig()
lg = logging.getLogger("demo")
hour = datetime.datetime.now().hour
print(1)
lg.debug(test := t"The thing happened with {expensive_function:!fn} {7} at hour {hour}.")
print(2)
lg.setLevel(logging.DEBUG)
lg.debug(test)
print(3)
will quickly print 1 and 2, then pause a second before 3 appears after DEBUG:demo:The thing happened with 14 at hour 16. Since expensive_function takes a single argument, the 7 is passed to the function while hour renders in the usual way.
The logger uses the embed function of tstring-util.
Metadata
Release files for template-string-logger 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| template_string_logger-1.0.tar.gz | 3.7 kB | Without provenance | Details for template_string_logger-1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| template_string_logger-1.0-py3-none-any.whl | Python 3 | none | any | Details for template_string_logger-1.0-py3-none-any.whl |
Total release size: 8.2 kB
Release files / template_string_logger-1.0.tar.gz
| Download URL | template_string_logger-1.0.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7c1d87cae84e46aebffbfdee2e82d535b180384e3e4ef301b06439615afefd92
|
|
BLAKE2b-256 checksum How to use checksums |
795c8cfa48dc79684332f0e0b25fcecebb28d9d7c8cb301be7bc657cb949a001
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.12
|
Release files / template_string_logger-1.0-py3-none-any.whl
| Download URL | template_string_logger-1.0-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cddf2e62efd4ecb8ed7e891eb1e2b2af51741f1bee171a6103602fe2d13f7039
|
|
BLAKE2b-256 checksum How to use checksums |
d013cd71977b913573a07b98e1dbff871daeb1910fdface0f8d9ef65984d255d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.12
|
Security for template-string-logger 1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.