Lightweight Python logger with log levels, rotation, colorization, async support, and working-directory-scoped file utilities
Project description
ntnlog
Lightweight Python logger with timestamped file output, caller stack tracing, and working-directory-scoped file utilities. Next-To-Nothing setup — just import and log.
Features
- Log levels:
TRACE,DEBUG,INFO,WARNING,ERROR,CRITICALwith per-instance and global thresholds - Caller stack tracing: Automatically records where in your code a log came from
- Timestamped file output: Logs written to daily files with no configuration required
- Log rotation: Size-based rotation with configurable backup count
- Console colorization: ANSI color output per log level, customizable per instance
- Exception capturing:
exception()attaches the active traceback automatically - Async support:
alog()andaexception()for async/await code - File utilities: Safe, working-directory-scoped file operations with error handling
- Thread-safe: File writes are protected by a per-instance lock
Installation
pip install ntnlog
Quick Start
from ntnlog import Logger, Level
log = Logger()
log("Application started")
log("Important message", console_message="") # also prints to stdout
log("Something suspicious", Level.WARNING) # WARNING level, no console
# Exception capturing — attaches the active traceback automatically
try:
do_something()
except Exception:
log.exception("Something went wrong")
# Async logging
await log.alog("Async message")
await log.aexception("Async error")
# Enable detailed call-stack tracing
log.enable_log_tracing(True)
log("Traced message")
# Named loggers — useful when multiple instances log to the same file
app_logger = Logger(name="app")
worker_logger = Logger(name="worker")
# Output: [2026-05-13 15:46:34][INFO][app][main.py:12] message
# [2026-05-13 15:46:34][INFO][worker][worker.py:8] message
# Level filtering — string or enum, both work
log = Logger(level=Level.WARNING)
log = Logger(level="warning")
# Log rotation
log = Logger(max_bytes=5_000_000, backup_count=3)
# Console colorization
log = Logger(colorize=True)
# Custom log directory
log = Logger(log_dir="my_logs")
# Project-aware frame filtering
log = Logger(project_dir="/path/to/project")
Configuration
from ntnlog.ntn_config import (
GLOBAL_LOGGING_ENABLED,
GLOBAL_LOG_TRACING_ENABLED,
GLOBAL_LOG_LEVEL,
GLOBAL_MAX_BYTES,
GLOBAL_BACKUP_COUNT,
GLOBAL_LOG_COLORS,
)
| Global | Default | Description |
|---|---|---|
GLOBAL_LOGGING_ENABLED |
True |
Master on/off switch for all loggers |
GLOBAL_LOG_TRACING_ENABLED |
True |
Master tracing switch |
GLOBAL_LOG_LEVEL |
Level.INFO |
Default minimum level when instance level is None |
GLOBAL_MAX_BYTES |
10_000_000 |
Default rotation threshold (10 MB) |
GLOBAL_BACKUP_COUNT |
1 |
Default number of backup files kept on rotation |
GLOBAL_LOG_COLORS |
see config | ANSI color code per level |
Per-instance controls:
log.enable_logging(False) # disable this logger
log.enable_log_tracing(True) # enable tracing for this logger
Modules
Logger (ntn_logging.py)
Main logging class. Writes timestamped, level-tagged entries to ./logs/<date>_logging.txt and optionally traces the full call stack to show exactly which file and line triggered the log.
File Utilities (ntn_file_utils.py)
Path and file verification scoped to the working directory:
file_verify_path(base, directory)— confirms a directory exists within the working dirfile_verify_file(base, filename, operator)— validates a file for read/write/execute
Utils (ntn_utils.py)
Working-directory-scoped path helpers with a clean exception-based API:
ntnlog.utils.get_working_dir()— returns the current working directoryntnlog.utils.resolve_path(path, must_exist=False)— resolves a path within the working directory, raisesValueErrorif it escapes
Configuration (ntn_config.py)
Global flags and defaults controlling logging behaviour across all logger instances.
Development
pip install -e ".[dev]"
pytest
pytest -v
pytest tests/test_ntn_logging.py
License
MIT
Author
Nathan T Nguyen
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ntnlog-0.5.0.tar.gz.
File metadata
- Download URL: ntnlog-0.5.0.tar.gz
- Upload date:
- Size: 22.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d84c51ee6f9e622fdd1e477fad98d4aa06208f91493a562022c350dfbc7eef1
|
|
| MD5 |
756f5c5e6c05c59c299c64f560a0369d
|
|
| BLAKE2b-256 |
21e7779a07069fd9abcd8610073903deb168e74407c3cf0d0759d36957bc92a8
|
Provenance
The following attestation bundles were made for ntnlog-0.5.0.tar.gz:
Publisher:
publish.yml on NhatNguyen5/ntnlog
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ntnlog-0.5.0.tar.gz -
Subject digest:
8d84c51ee6f9e622fdd1e477fad98d4aa06208f91493a562022c350dfbc7eef1 - Sigstore transparency entry: 1581140913
- Sigstore integration time:
-
Permalink:
NhatNguyen5/ntnlog@bbf3711d9b4baee5e053a72b0c4a2a17a2c325b2 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/NhatNguyen5
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bbf3711d9b4baee5e053a72b0c4a2a17a2c325b2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ntnlog-0.5.0-py3-none-any.whl.
File metadata
- Download URL: ntnlog-0.5.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc252aa04c15cd34dd7a29d601f740c59afce4c536b7fd0e66df83ec36715897
|
|
| MD5 |
a6b1055384eba9f5ff2531df99abc612
|
|
| BLAKE2b-256 |
506336956296942c29ee3611255eca1fb7a2897c162e79920099d9492988661f
|
Provenance
The following attestation bundles were made for ntnlog-0.5.0-py3-none-any.whl:
Publisher:
publish.yml on NhatNguyen5/ntnlog
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ntnlog-0.5.0-py3-none-any.whl -
Subject digest:
cc252aa04c15cd34dd7a29d601f740c59afce4c536b7fd0e66df83ec36715897 - Sigstore transparency entry: 1581141158
- Sigstore integration time:
-
Permalink:
NhatNguyen5/ntnlog@bbf3711d9b4baee5e053a72b0c4a2a17a2c325b2 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/NhatNguyen5
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bbf3711d9b4baee5e053a72b0c4a2a17a2c325b2 -
Trigger Event:
release
-
Statement type: