Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nba_log-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

nba_log-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

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

Hashes for nba_log-0.1.0.tar.gz
Algorithm Hash digest
SHA256 909405bc8c0758d0f470ea43d081ea0ec8f2589702aab352bd9fdd385f324611
MD5 9d80cb69c88b4c3e443b08173545f52c
BLAKE2b-256 2602c702be403f068c85e3482a4e7e59b2b8c0a9710a1a36c039ca4d720e4b38

See more details on using hashes here.

Provenance

The following attestation bundles were made for nba_log-0.1.0.tar.gz:

Publisher: publish.yaml on ABA-Developer/nba-log

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for nba_log-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 97d54488bbc2e0937a6567785c4f9545f47a624456437f9560324c1de3455d81
MD5 1d1b87db63a857b0192f6c6243240414
BLAKE2b-256 2bd66d82511555307cee4d3ee2c06e17a95449e9ad28d0bd2eae51f769e3e379

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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