Skip to main content

Unified logging utilities for Laplace applications

Project description

laplace_log

A small, opinionated logging helper built on top of Python’s standard logging module.

laplace_log is designed for multi-module / multi-process scientific or application projects where you want:

  • One central logger initialization
  • Logs from your app + third‑party libraries
  • Clear application names in logs (e.g. laplace.opt)
  • Automatic daily log folders
  • Simple log.info(...) usage everywhere
  • print() statements captured into logs

No magic, no external dependencies — just structured, predictable logging.


Features

  • ✅ Root logger configuration (captures library logs)
  • ✅ Application‑named logger (app_name)
  • ✅ File + console handlers with independent levels
  • ✅ Automatic folder structure: logs/YYYY-MM-DD/app_name.log
  • print() and stderr redirection into logs
  • ✅ Simple log.info(...) helper available everywhere
  • ✅ Singleton design (initialize once, use everywhere)

Installation

Install with pip:

pip install laplace-log

Quick Start

1. Initialize the logger once (entry point)

from laplace_log.log_lhc import LoggerLHC, log

LoggerLHC(
    app_name="laplace.opt",
    file_level="debug",
    console_level="info",
)

log.info("Starting OptWindow...")

2. Use logging anywhere

from laplace_log.log_lhc import log

log.debug("Debug message")
log.info("Information")
log.warning("Something looks odd")
log.error("Something went wrong")

No need to pass logger instances around.


Log Output Example

2026-01-20 10:21:47 [INFO] [laplace.opt] Starting OptWindow...
2026-01-20 10:21:48 [WARNING] [numpy] overflow encountered in exp
2026-01-20 10:21:49 [INFO] [root] A print statement
  • App logs use your app_name
  • Library logs keep their original logger names
  • print() statements appear as root

Folder Structure

logs/
└── 2026-01-20/
    └── laplace_opt.log
  • A new folder is created each day
  • Dots in app_name are replaced by underscores for filenames

Design Overview

Root logger

The root logger is configured with:

  • File handler (persistent logs)
  • Console handler (stdout)

This ensures all third‑party libraries are captured automatically.

Application logger

Each app uses its own named logger:

logging.getLogger("laplace.opt")

This name appears in log records and helps identify the source clearly.


The log Helper

log is a lightweight helper object:

from laplace_log.log_lhc import log
log.info("Hello")

Internally, it forwards calls to the initialized LoggerLHC instance.

If logging is used before initialization, an explicit error is raised:

RuntimeError: Logger not initialized! Call LoggerLHC(app_name, ...) first.

This avoids silent failures.


Print Redirection

All print() and sys.stderr output is redirected:

  • Printed normally to the console
  • Also logged at INFO level via the root logger

This is useful for:

  • Legacy code
  • Debug prints
  • Third‑party libraries using print

Configuration Options

LoggerLHC(
    app_name: str,
    log_root: Path | str | None = None,
    file_level: str = "debug",
    console_level: str = "info",
)
Parameter Description
app_name Logical name of your application (laplace.opt, lapalce.server, …)
log_root Base folder for logs (default: current working directory)
file_level Minimum level written to file
console_level Minimum level printed to console

Intended Use Cases

  • Scientific applications (optimization, simulations)
  • Multi‑process systems (master / worker / optimizer)
  • GUI + backend projects
  • Long‑running experiments
  • Any project needing clean, centralized logs

License

GPL-3.0 license

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

laplace_log-0.1.1.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

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

laplace_log-0.1.1-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file laplace_log-0.1.1.tar.gz.

File metadata

  • Download URL: laplace_log-0.1.1.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for laplace_log-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5b4e4107c630aa2370ef10d0e9ce7ff62207374d45a9e66411e40994201a686e
MD5 5c66ab5721c245d0b1f4c45f7ceb2c66
BLAKE2b-256 12a0946a2f5e879189cf7118ea3c40d90af923ba0db40ce8f7e29851a9d4e844

See more details on using hashes here.

File details

Details for the file laplace_log-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: laplace_log-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for laplace_log-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db5b573cee4efb0e26c3111f16506ed5ca599dae322bb784bdbb6817094549b5
MD5 6c15baf8233914c743fa421a3be53439
BLAKE2b-256 0b8f14ef3fcab052b50e9567536566c47abd133acfec17659616cf1e333618b7

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