Skip to main content

no log tears

Latest Version Python Supported Versions MyPy Strict Test Coverage Downloads GitHub stars

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=INFO and your process will log at the INFO level. Or LOGGING__FORMATTER=verbose to use the predefined verbose formatter.
    • capture python warnings: log warnings.warn messages to the logger.
  • mixins: easily add logging to your classes.
    • LoggerMixin: adds _logger property to your instance and adds self to log records (instance hex id).
    • LoggableMixin: converts instance to string based on logging level of the class.
    • LogMixin: adds a _log to your class and allows you to bind additional context to loggers with _log_extra method.
  • 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

Metadata

Release files for no-log-tears 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for no-log-tears 0.2.1
File Size Uploaded Provenance Actions
no_log_tears-0.2.1.tar.gz 13.3 kB With provenance Details for no_log_tears-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for no-log-tears 0.2.1
File Interpreter ABI Platform Actions
no_log_tears-0.2.1-py3-none-any.whl Python 3 none any Details for no_log_tears-0.2.1-py3-none-any.whl

Total release size: 29.3 kB

Release files / no_log_tears-0.2.1.tar.gz

Download URL no_log_tears-0.2.1.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
94127ee359092505226c70f1f29c5831e4ad5d3f45cfb7506a79e7292d0be626
BLAKE2b-256 checksum
How to use checksums
0d5b6aae7dfb4f2d7701e4f45a8aeec8a00d413c20feb8c5430793a7d0c4ec73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 24, 2025.

Transparency log

Release files / no_log_tears-0.2.1-py3-none-any.whl

Download URL no_log_tears-0.2.1-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a83f980ff4ae040f68c3a0ce3eb86f6b5c2426402ea178300e01ee938b739d96
BLAKE2b-256 checksum
How to use checksums
e4990685d47e94c61bc56dd867a0ee08f9923554f71f26fe39bd74ce87c2c676
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 24, 2025.

Transparency log

Security for no-log-tears 0.2.1

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for no_log_tears-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 24, 2025.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page