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.
- ✅ 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()andstderrredirection into logs - ✅ Simple
log.info(...)helper available everywhere - ✅ Singleton design (initialize once, use everywhere)
- ✅ Provide an error hook (to avoid silent failures such as PyQt signals)
Install with pip:
pip install laplace-logfrom laplace_log import LoggerLHC, log
LoggerLHC(
app_name="laplace.opt",
file_level="debug",
console_level="info",
)
log.info("Starting OptWindow...")from laplace_log 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.
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
logs/
└── 2026-01-20/
└── laplace_opt.log
- A new folder is created each day
- Dots in
app_nameare replaced by underscores for filenames
The root logger is configured with:
- File handler (persistent logs)
- Console handler (stdout)
This ensures all third‑party libraries are captured automatically.
Each app uses its own named logger:
logging.getLogger("laplace.opt")This name appears in log records and helps identify the source clearly.
log is a lightweight helper object:
from laplace_log 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.
All print() and sys.stderr output is redirected:
- Printed normally to the console
- Also logged at
INFOlevel via the root logger
This is useful for:
- Legacy code
- Debug prints
- Third‑party libraries using
print
To avoid silent failures, an error hook can be loaded:
from laplace_log import uncaught_exceptionThis import will by itself make sure that no error will be missed. This is especially useful for PyQt signal errors.
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 |
- Scientific applications (optimization, simulations)
- Multi‑process systems (master / worker / optimizer)
- GUI + backend projects
- Long‑running experiments
- Any project needing clean, centralized logs
GPL-3.0 license