Skip to main content

logging-setup

PyPI Python License: MIT Code style Built on

A ready-made configuration for Python's standard logging module. Call init_logging() once, and the whole project gets colored console output, daily log files, and automatic cleanup.

Features

  • Colored console output (DEBUG white, INFO cyan, WARNING yellow, ERROR red, CRITICAL bright red)
  • STDOUT gets messages up to WARNING, STDERR gets ERROR and above
  • Daily log files (UTC):
    • logs/app-YYYY-MM-DD.log for DEBUG to WARNING
    • logs/error-YYYY-MM-DD.log for ERROR and CRITICAL
  • Old logs are deleted automatically (default: older than 30 days), once at startup and then every day
  • No need for logging.getLogger(__name__): logging.info(...) shows the real module name (for example app.bot) instead of root
  • Uncaught exceptions in the main thread and in other threads are logged as errors
  • Noisy libraries (urllib3, aiohttp, selenium, telethon, pyrogram, asyncio, apscheduler) are limited to WARNING
  • Calling init_logging() twice is safe: the second call is ignored

Requirements

Installation

pip install loggingsetup

With uv:

uv add loggingsetup

The package name is loggingsetup, but the import name is logging_setup.

Quick start

In your main script, call it once:

import logging
from logging_setup import init_logging

init_logging()

logging.info("Hello World!")

In every other module, just use the standard logging:

import logging

def run():
    logging.info("Bot started")
    logging.error("Something went wrong")

Example output:

2026-10-20 09:42:16 | INFO     | app.bot | Bot started
2026-10-20 09:42:16 | ERROR    | app.bot | Something went wrong

logger = logging.getLogger(__name__) still works if you prefer it.

Parameters

Parameter Type Default Description
directory str "logs" Folder for log files
enable_console bool True Turn console output on or off
delete_old_logs bool True Turn automatic cleanup on or off
days_to_delete_old_logs int 30 Delete logs older than this many days
init_logging(directory="my_logs", enable_console=False, days_to_delete_old_logs=14)

Project structure

logging_setup/
├── __init__.py          # exports init_logging
├── my_setup.py          # main setup function
├── formats.py           # color formatter, rotating handler, module name factory
├── filters.py           # level filters, exception hooks
└── cleanup_old_logs.py  # background cleanup of old log files

Notes

  • The module name is calculated from the file path relative to the current working directory. Run your project from its root folder, so app/bot.py is shown as app.bot.
  • The entry script is shown as main, not __main__.
  • Old files are deleted only by the cleanup job, not by backupCount.

Metadata

Release files for loggingsetup 0.0.2

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

Source distribution (sdist)

Source distribution for loggingsetup 0.0.2
File Size Uploaded Provenance
loggingsetup-0.0.2.tar.gz 6.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for loggingsetup 0.0.2
File Interpreter ABI Platform
loggingsetup-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / loggingsetup-0.0.2.tar.gz

Download URL loggingsetup-0.0.2.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
037a6ad511314ca4faeab165405d4f0282fae07275664c7c2e26e49e1cfe22c1
BLAKE2b-256 checksum
How to use checksums
8e2bf7a07e76a999d804090bcb6a9ef24f949dca02589c4a4a9dedee2be4ba59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / loggingsetup-0.0.2-py3-none-any.whl

Download URL loggingsetup-0.0.2-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5d21dd164a9ea5f28a9e44b10951d78e92ef56e6175325aa689533621eb996b
BLAKE2b-256 checksum
How to use checksums
a06b60ec4b8c8b73b9d48f2711af0baa5554c3eaeaa1c0791030a30b4d0bb2d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for loggingsetup 0.0.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

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