Skip to main content

A Python library that augments the standard logging module

Project description

logenrich v1.0.1

A Python library that augments the standard logging module with simplified, INI-driven configuration.

Prerequisites

  • Python >=3.14

Installation

pip install logenrich

Usage

Import setup_logger directly from the logenrich package:

from logenrich import setup_logger

logger = setup_logger(__name__)
logger.info("Hello from logenrich!")

setup_logger searches upward from the current working directory for a logging.ini file and caches the resolved path for subsequent calls. If no configuration file is found, it falls back to basicConfig at INFO level.

Optional parameters

Parameter Type Default Description
name str (required) Logger name, typically __name__.
conf_dir `str None` Current working directory
log_ini `str None` "logging.ini"

Architecture

flowchart TD
    A[caller: setup_logger] --> B{cache valid?}
    B -- yes --> E[getLogger]
    B -- no --> C[_find_logging_ini\nwalk up tree]
    C --> D{logging.ini\nfound?}
    D -- yes --> F[fileConfig\nload INI]
    D -- no --> G[basicConfig\nINFO level]
    F --> E
    G --> E
    E --> H[Logger instance]

Configuration

Place a logging.ini file in your project root. The bundled default configures two handlers:

Handler Target Format
Console sys.stderr %(asctime)s - %(name)s - %(levelname)s - %(message)s
File logenrich.log %(asctime)s [%(levelname)s] %(name)s - %(message)s

Example logging.ini:

[loggers]
keys=root

[handlers]
keys=consoleHandler,fileHandler

[formatters]
keys=logFormatter,consoleFormatter

[logger_root]
level=INFO
handlers=consoleHandler,fileHandler

[handler_consoleHandler]
class=StreamHandler
formatter=consoleFormatter
args=(sys.stderr,)

[handler_fileHandler]
class=FileHandler
formatter=logFormatter
args=('logenrich.log', 'a')

[formatter_logFormatter]
format=%(asctime)s [%(levelname)s] %(name)s - %(message)s

[formatter_consoleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s

Development

Requires Poetry 2.2.

Setup

poetry install

Running Tests

poetry run pytest --cov=logenrich tests --cov-report html

Formatting and Linting

poetry run black logenrich; poetry run pylint logenrich

Pylint must score 10/10. Minimum test coverage is 80%.

Publishing to PyPI

Prerequisites

  • A PyPI account with an API token.

Configure the token

poetry config pypi-token.pypi <your-token>

Build and publish

poetry publish --build

This builds the source distribution and wheel, then uploads them to PyPI in one step.

Note: PyPI releases are immutable. Once a version is published, it cannot be overwritten.
To fix a mistake, yank the release via the PyPI web UI and publish a new version.

Changelog

See CHANGELOG.md for the full version history.

License

MIT

Author

Ronaldo Webb <ron@ronella.xyz>

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

logenrich-1.0.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

logenrich-1.0.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file logenrich-1.0.1.tar.gz.

File metadata

  • Download URL: logenrich-1.0.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.14.4 Windows/11

File hashes

Hashes for logenrich-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ff0f282fe6349d0d215a2e1ca87573c03ebbffa5a9b345e0fd0430b1132996fc
MD5 e107c29143efa45ccf038d594fd25cc9
BLAKE2b-256 31d517f254fc061dbef24a9b75da4e870eb9a100d89f4f694e8fd80d9dfa2da2

See more details on using hashes here.

File details

Details for the file logenrich-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: logenrich-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.14.4 Windows/11

File hashes

Hashes for logenrich-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fee5a0f1a1d87f0b57c14ecf5cc95c41ccf50a1177eedde315c5ee0ea91fc240
MD5 69605ca104f3724147967acf7204682d
BLAKE2b-256 9284b38218f151e48a3d5df3fe59c3ec3c3d7127e40250c81659ccdd1eba8e35

See more details on using hashes here.

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