A ported Go logger with ANSI styling and file rotation
Project description
nba-log
A lightweight, synchronized Python logger with ANSI color support and automatic file rotation. Ported from a Golang logging utility to provide a clean, "tagged" logging experience for console and file-based output.
Features
- 🎨 ANSI Styling: Full support for foreground, background, and font styles (Bold, Italic, etc.).
- 🏷️ Tagged Logs: Every log entry includes a fixed-width tag (7 characters) for easy visual alignment.
- 📂 File Rotation: Background thread support to rotate logs at a specific time (e.g., daily at midnight).
- 🚀 Synchronous & Simple: Built for reliability and ease of use in Python scripts and applications.
Installation
You can install the library via pip:
pip install nba-log
Quick Start
from nba_log import Logger
# Initialize with a tag and debug mode enabled
log = Logger("GPIO", debug_mode=True)
# Apply standard colors (Info: White, Warn: Yellow, Error: Red, etc.)
log.set_default_style()
log.info("System initialized")
log.debug("Checking sensors...") # Only visible if debug_mode=True
log.error("Failed to reach server")
Advanced Usage
File Logging & Auto-Rotation
Enable persistent logging to a directory. The logger will automatically append the date to the filename.
import time
from nba_log import Logger
# 1. Setup Logger
log = Logger("SERVER", debug_mode=True)
log.set_default_style()
# 2. Enable file writing (Directory Path, File Prefix)
log.set_write_files_enable("./logs", "api_service")
# 3. Schedule rotation at 00:00 (Midnight)
# The logger handles the timing in the background
log.change_file_routine(0, 0)
log.info("Continuous logging started. Press Ctrl+C to stop.")
try:
# 4. Infinite loop to print every 1 minute
while True:
log.info("Heartbeat: Service is healthy")
# Wait for 5 seconds
time.sleep(5)
except KeyboardInterrupt:
log.warn("Logging stopped by user.")
Custom Styling
You can override default styles using the provided constants. Styles are lists of ANSI codes.
from nba_log import Logger, StyleFgYellow, StyleFontBold, StyleBgRed
log = Logger("APP", True)
# Custom style for warnings: Bold and Yellow text
log.warn_style = [StyleFontBold, StyleFgYellow]
# Custom style for fatal errors: Bold black text on a Red background
log.fatal_style = [StyleFontBold, StyleBgRed]
log.warn("This is a custom warning style!")
Project details
Release history Release notifications | RSS feed
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 nba_log-0.1.0.tar.gz.
File metadata
- Download URL: nba_log-0.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
909405bc8c0758d0f470ea43d081ea0ec8f2589702aab352bd9fdd385f324611
|
|
| MD5 |
9d80cb69c88b4c3e443b08173545f52c
|
|
| BLAKE2b-256 |
2602c702be403f068c85e3482a4e7e59b2b8c0a9710a1a36c039ca4d720e4b38
|
Provenance
The following attestation bundles were made for nba_log-0.1.0.tar.gz:
Publisher:
publish.yaml on ABA-Developer/nba-log
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nba_log-0.1.0.tar.gz -
Subject digest:
909405bc8c0758d0f470ea43d081ea0ec8f2589702aab352bd9fdd385f324611 - Sigstore transparency entry: 815312493
- Sigstore integration time:
-
Permalink:
ABA-Developer/nba-log@2854c19e5a762b69af3c9c4decb427fd473ba09e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ABA-Developer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@2854c19e5a762b69af3c9c4decb427fd473ba09e -
Trigger Event:
release
-
Statement type:
File details
Details for the file nba_log-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nba_log-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97d54488bbc2e0937a6567785c4f9545f47a624456437f9560324c1de3455d81
|
|
| MD5 |
1d1b87db63a857b0192f6c6243240414
|
|
| BLAKE2b-256 |
2bd66d82511555307cee4d3ee2c06e17a95449e9ad28d0bd2eae51f769e3e379
|
Provenance
The following attestation bundles were made for nba_log-0.1.0-py3-none-any.whl:
Publisher:
publish.yaml on ABA-Developer/nba-log
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nba_log-0.1.0-py3-none-any.whl -
Subject digest:
97d54488bbc2e0937a6567785c4f9545f47a624456437f9560324c1de3455d81 - Sigstore transparency entry: 815312496
- Sigstore integration time:
-
Permalink:
ABA-Developer/nba-log@2854c19e5a762b69af3c9c4decb427fd473ba09e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ABA-Developer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@2854c19e5a762b69af3c9c4decb427fd473ba09e -
Trigger Event:
release
-
Statement type: