NoLogTears is a simple extension of Python's built-in logging library, designed to make logging easier, more efficient, and headache-free—no more tears over log management.
Project description
no log tears
I personally found the built-in logging library to be a bit messy to use, so I created this library. Now, logging is easy, and there are no more tears!
Features
- easy to configure: set up logging via environment variables or a configuration file (thanks to pydantic-settings).
- extended base configuration:
- predefined configuration: use built-in formatters and handlers or create your own.
- customizable default configuration with environment variables: e.g.
LOGGING__LEVEL=INFOand your process will log at theINFOlevel. OrLOGGING__FORMATTER=verboseto use the predefinedverboseformatter. - capture python warnings: log
warnings.warnmessages to the logger.
- mixins: easily add logging to your classes.
- LoggerMixin: adds
_loggerproperty to your instance and addsselfto log records (instance hex id). - LoggableMixin: converts instance to string based on logging level of the class.
- LogMixin: adds a
_logto your class and allows you to bind additional context to loggers with_log_extramethod.
- LoggerMixin: adds
- log context: easily bind additional context to loggers.
- traceback limit: Set the number of stack frames to display in log messages.
Dependencies
- python 3.9+
Optional:
- pydantic
- pydantic-settings
Installation
pip install no-log-tears
Usage
Simple logging (execute python script with LOGGING__LEVEL=INFO environment variable):
from no_log_tears import get_logger
log = get_logger(__name__)
log.info("Hello, world!")
# Output: `2025-02-19 20:42:28,928 INFO __main__ Hello, world!`
Set up logging with a configuration file:
# logging.yaml
root:
level: INFO
handlers: [ console ]
handlers:
console:
formatter: custom
stream: ext://sys.stdout
formatters:
custom:
(): no_log_tears.formatters.SoftFormatter
fmt: '%(asctime)s %(levelname)s %(message)s %(my_field)s %(__other__)s'
# automatically loads logging configuration from `logging.yaml` on import
from no_log_tears import get_logger
log = get_logger(__name__)
log.info("Hello, world!", my_field="my_value", my_other_field="my_other_value")
# Output: `2025-02-19 20:42:28,928 INFO Hello, world! my_value {'my_other_field': 'my_other_value'}`
Use the LogMixin class to easily log messages with additional context:
from no_log_tears import LogMixin
class MyClass(LogMixin):
def __init__(self, my_field: str) -> None:
self.__my_field = my_field
def do_stuff(self, foo: str) -> str:
# bind `foo` value to the logger
log = self._log(foo=foo)
# log a message with `foo` value
log.debug("Doing stuff ...")
spam = foo + ":eggs"
log = log(spam=spam)
# log a message with `foo`, `spam` and `magic` values
log.info("Stuff done!", magic="Yes!")
return spam
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file no_log_tears-0.2.1.tar.gz.
File metadata
- Download URL: no_log_tears-0.2.1.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94127ee359092505226c70f1f29c5831e4ad5d3f45cfb7506a79e7292d0be626
|
|
| MD5 |
480290d6bf226f84446cf6a1f31af83e
|
|
| BLAKE2b-256 |
0d5b6aae7dfb4f2d7701e4f45a8aeec8a00d413c20feb8c5430793a7d0c4ec73
|
Provenance
The following attestation bundles were made for no_log_tears-0.2.1.tar.gz:
Publisher:
publish.yaml on zerlok/no-log-tears
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
no_log_tears-0.2.1.tar.gz -
Subject digest:
94127ee359092505226c70f1f29c5831e4ad5d3f45cfb7506a79e7292d0be626 - Sigstore transparency entry: 173845580
- Sigstore integration time:
-
Permalink:
zerlok/no-log-tears@1dddf5f072ea30232b16d61c4baa3c8a35b1cf12 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/zerlok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@1dddf5f072ea30232b16d61c4baa3c8a35b1cf12 -
Trigger Event:
release
-
Statement type:
File details
Details for the file no_log_tears-0.2.1-py3-none-any.whl.
File metadata
- Download URL: no_log_tears-0.2.1-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a83f980ff4ae040f68c3a0ce3eb86f6b5c2426402ea178300e01ee938b739d96
|
|
| MD5 |
fd0cee772bb1caa55f8fa07f4ceb5776
|
|
| BLAKE2b-256 |
e4990685d47e94c61bc56dd867a0ee08f9923554f71f26fe39bd74ce87c2c676
|
Provenance
The following attestation bundles were made for no_log_tears-0.2.1-py3-none-any.whl:
Publisher:
publish.yaml on zerlok/no-log-tears
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
no_log_tears-0.2.1-py3-none-any.whl -
Subject digest:
a83f980ff4ae040f68c3a0ce3eb86f6b5c2426402ea178300e01ee938b739d96 - Sigstore transparency entry: 173845583
- Sigstore integration time:
-
Permalink:
zerlok/no-log-tears@1dddf5f072ea30232b16d61c4baa3c8a35b1cf12 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/zerlok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@1dddf5f072ea30232b16d61c4baa3c8a35b1cf12 -
Trigger Event:
release
-
Statement type: