Skip to main content

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

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:

from no_log_tears import get_logger, configure_logging, INFO

configure_logging(level=INFO)
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.SomeFormatter
    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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

no_log_tears-0.1.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

no_log_tears-0.1.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file no_log_tears-0.1.0.tar.gz.

File metadata

  • Download URL: no_log_tears-0.1.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for no_log_tears-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7ca44365bea6db078302b0efd2fe0e38330f983f446fb73752e6dae19f4783e4
MD5 f9b4bf6e8447b2866477157c89d83c76
BLAKE2b-256 3085ecc79339e07ae1bfb34242bdec9af99f572f41fd43c66c55e518b52ad3fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for no_log_tears-0.1.0.tar.gz:

Publisher: publish.yaml on zerlok/no-log-tears

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file no_log_tears-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: no_log_tears-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for no_log_tears-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9c5a6e7458387386db3b91cf0bb2d5ef82121453ad8e0b596d8449e4969083ea
MD5 f65bb7a42d2a56bb0bcb7e2ca61bc314
BLAKE2b-256 8e389494fa5b9f454334f126533e8446f6f59a2faf548e74b831e03d90f9207f

See more details on using hashes here.

Provenance

The following attestation bundles were made for no_log_tears-0.1.0-py3-none-any.whl:

Publisher: publish.yaml on zerlok/no-log-tears

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page