Skip to main content

Creates a reasonable logging configuration for a Python project

Project description

readylog

Readylog is a logging configuration template for Python's logging.

Usage

Basic example:

# my_app.py

from logging.config import dictConfig as configure_logging
from logging import getLogger
from pathlib import Path

from platformdirs import user_log_dir
from readylog import create_dict_config


def setup_logging() -> None:
    app_name = "my_app"
    author = "Me"

    log_dir = Path(user_log_dir(app_name, author))
    log_dir.mkdir(parents=True, exist_ok=True)

    logging_config = create_dict_config(log_dir / "debug.log", app_name)
    configure_logging(logging_config)


logger = getLogger(__name__)
setup_logging()

logger.debug("This should be logged")

Documentation

readylog's public objects

DEFAULT_CORE_LOG_FORMAT = "{levelname} {name}({lineno}), {funcName}: {message}"
DEFAULT_CONSOLE_LOG_FORMAT = DEFAULT_CORE_LOG_FORMAT
DEFAULT_FILE_LOG_FORMAT = "{} {}".format("{asctime}.{msecs:03.0f} ", DEFAULT_CORE_LOG_FORMAT)
DEFAULT_CONSOLE_LOG_TIME_FORMAT = "%H:%M:%S"
DEFAULT_FILE_LOG_TIME_FORMAT = DEFAULT_CONSOLE_LOG_TIME_FORMAT


def create_dict_config(
    logfile: Path | str,
    app_name: str,
    console_log_level: str | int = "WARNING",
    console_log_format: str = DEFAULT_CONSOLE_LOG_FORMAT,
    console_log_time_format: str = DEFAULT_CONSOLE_LOG_TIME_FORMAT,
    file_log_level: str | int = "DEBUG",
    file_log_format: str = DEFAULT_FILE_LOG_FORMAT,
    file_log_time_format: str = DEFAULT_CONSOLE_LOG_TIME_FORMAT,
    console_handler_factory: Callable = StreamHandler,
    file_handler_factory: Callable = FileHandler,
    additional_logger_names: tuple[str] = (),
    root_logger_level: str | int = "WARNING",
) -> dict[str, str]:

Arguments:

  • logfile: name of the log file where to save the logs
  • app_name: name of your app (will be used as a logger name)

Keyword Arguments:

  • console_log_level: minimum log level for the console log
  • console_log_format: console log line format in "{" style
  • file_log_level: minimum log level for the file log
  • file_log_format: file log line format in "{" style
  • console_handler_factory: the factory for the stream handler
  • file_handler_factory: the factory for the file handler
  • additional_logger_names: here you can put all the other logger names which you want to include in your log. Use this when you have projects with uv workspaces and want to see logs from workspace members rather than just from you main app.
  • root_logger_lever: minimum level to display in you root log

Root Log file

Root log will be output to console and to a file. The path and name of the root log file is derived from the logfile path, but the file name stem has a "_root" suffix.

For example if logfile path is /home/my_user/my_app/debug.log, then the root log will be in /home/my_user/my_app/debug_root.log.

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

readylog-0.6.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

readylog-0.6.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file readylog-0.6.1.tar.gz.

File metadata

  • Download URL: readylog-0.6.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for readylog-0.6.1.tar.gz
Algorithm Hash digest
SHA256 1807bd8938ff10320c59d1458e831cea3a88b8d6d20bccf990b2272161b1edbf
MD5 4e4d600a68399e9603ad5da787e0c28a
BLAKE2b-256 04defbd38008ac2dbcba0e69c575027e9323ed910aa4eb753280788a733696f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for readylog-0.6.1.tar.gz:

Publisher: continuous-delivery.yml on fleetingbytes/readylog

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

File details

Details for the file readylog-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: readylog-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for readylog-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1cb7fcaf81e160f2afe24adad5c3a820299669a3a68a161dd71a7d9dd0607cfc
MD5 7ce2314c0d4a7e3ee1dd21f614346ac3
BLAKE2b-256 b5ffb6f4c85fe45d148fe81e3e589556b13c0ba5c3782676d2fffa76df98e243

See more details on using hashes here.

Provenance

The following attestation bundles were made for readylog-0.6.1-py3-none-any.whl:

Publisher: continuous-delivery.yml on fleetingbytes/readylog

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