Skip to main content

arlogi logo

arlogi - Advanced Logging Library

arlogi is a robust, type-safe logging library for Python that extends the standard logging module with modern features, caller attribution, file rotation, and premium aesthetics.

Full Documentation

Features

  • Caller Attribution: Track log calls across function boundaries using caller_depth.
  • Custom TRACE Level: Level 5 logging for ultra-detailed debugging.
  • Premium Colored Output: Uses rich for beautiful, readable console logs with automatic traceback support.
  • Structured JSON Logging: Out-of-the-box support for JSON logging, file rotation, and log retention.
  • Module-Specific Configuration: Easily set different log levels for different parts of your application.
  • Dedicated Destination Loggers: Log specific events only to JSON or Syslog without cluttering the console.
  • Type Safety: Fully type-checked with LoggerProtocol and supports modern Python types.

Installation

# Using uv (recommended)
uv add arlogi

# Or using pip
pip install arlogi

Usage

Basic Setup

from arlogi import setup_logging, get_logger

# 1. Initialize logging
setup_logging(level="INFO")

# 2. Get a logger
logger = get_logger("my_app")
logger.info("Application started", caller_depth=0)
logger.trace("This won't be visible because level is INFO")

Module-Specific Levels

from arlogi import setup_logging, TRACE

setup_logging(
    level="INFO",
    module_levels={
        "my_app.db": "DEBUG",
        "my_app.network": TRACE
    }
)

JSON File Rotation and Syslog

from arlogi import setup_logging

setup_logging(
    level="INFO",
    json_file_name="logs/app.jsonl",
    rotate_schedule="day",
    rotate_retention_count=7,
    use_syslog=True,
    syslog_address="/dev/log"
)

Dedicated Loggers

Sometimes you want to log specific data ONLY to a file or a remote system:

from arlogi import get_json_logger, get_syslog_logger, cleanup_json_logger

# Logs only to JSON, not to console
audit_logger = get_json_logger("audit", "logs/audit.jsonl")
audit_logger.info("User logged in", user_id=123)

# Logs only to Syslog
syslog_logger = get_syslog_logger("security")
syslog_logger.warning("Failed login attempt")

# Resource cleanup when done
cleanup_json_logger("audit")

Integration with Other Libraries

arlogi works seamlessly with any third‑party library that uses the standard logging module.

Default INFO when arlogi is not imported

If your application never imports arlogi, the standard logging defaults (WARNING) remain unchanged. To get a simple INFO level without pulling in arlogi, add a tiny bootstrap:

import logging
logging.basicConfig(level=logging.INFO)

Overriding the level when you do use arlogi

Initialize arlogi with setup_logging() early in your program. setup_logging() allows fine-grained control over levels and handlers.

Making third‑party libraries respect the chosen level

All libraries that obtain a logger via logging.getLogger(name) inherit the level from the nearest ancestor – usually the root logger configured via setup_logging(). If a library forces its own level, reset it:

import logging
logging.getLogger("some_lib").setLevel(logging.NOTSET)  # inherit from root

Quick bootstrap example

# bootstrap.py
import os, logging
from arlogi import setup_logging

def configure_logging():
    if os.getenv("USE_ARLOGI", "0") == "1":
        level = os.getenv("ARLOGI_LEVEL", "INFO").upper()
        setup_logging(level=level)
    else:
        logging.basicConfig(level=logging.INFO)

# main.py
from bootstrap import configure_logging
configure_logging()

With this pattern you get:

  • Default INFO when arlogi is absent.
  • Full control over the log level when you import arlogi.
  • Automatic inheritance for any library that uses logging.

Using TRACE in your library

If you are developing a library and want to use the TRACE level:

  1. The Safe Way (Recommended): Use logger.log(TRACE, ...) This works regardless of when your library is imported relative to arlogi setup.

    import logging
    try:
        from arlogi import TRACE
    except ImportError:
        TRACE = 5
    
    logger = logging.getLogger(__name__)
    
    def complex_operation():
        logger.log(TRACE, "Step 1 of complex operation...")
    
  2. The method way: logger.trace(...) This only works if arlogi is configured before your library creates its logger instance.

Lazy Initialization (Safe Use of .trace)

If you must use .trace() in your library but aren't sure if arlogi is setup yet, you can use lazy initialization with LoggerProtocol for type safety:

from arlogi import LoggerProtocol, get_logger

_logger: LoggerProtocol | None = None

def log() -> LoggerProtocol:
    """Get or create the logger for this module lazily."""
    global _logger
    if _logger is None:
        _logger = get_logger("my_lib.cache")
    return _logger

Advanced Configuration

Centralized Logging Setup

For full control over console output, file paths, and remote handlers:

from arlogi import setup_logging

setup_logging(
    level="INFO",
    module_levels={"app.db": "DEBUG"},
    json_file_name="logs/app.jsonl",
    show_time=True,
    show_level=True,
    show_path=False
)

Direct Factory API

Alternatively, LoggerFactory.setup(...) provides the exact same functionality via the factory class:

from arlogi import LoggerFactory

LoggerFactory.setup(
    level="INFO",
    module_levels={"app.db": "DEBUG"}
)

Color Schemes

arlogi comes with a refined default color scheme:

  • TRACE / DEBUG: Grey / Cyan
  • INFO: Green
  • WARNING: Yellow
  • ERROR / CRITICAL: Red

Development

Run tests with pytest:

uv run pytest

Check code formatting and linting:

uv run ruff check .

Build local documentation:

uv run mkdocs build

License

MIT License - see LICENSE file for details.

Download files

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

Source Distribution

arlogi-0.608.0.tar.gz (506.6 kB view details)

Uploaded Source

Built Distribution

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

arlogi-0.608.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file arlogi-0.608.0.tar.gz.

File metadata

  • Download URL: arlogi-0.608.0.tar.gz
  • Upload date:
  • Size: 506.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for arlogi-0.608.0.tar.gz
Algorithm Hash digest
SHA256 9a99bb3bc78ce58201f2d04f4c46e042d7603928df1020b52ad873bc918b5c39
MD5 2dc76b4bcfecd2d5283213f9789042b6
BLAKE2b-256 06796e9f0dd57b1c6ceaa1c6b5774869064e4566b76eadceb5055db3ffd93c31

See more details on using hashes here.

File details

Details for the file arlogi-0.608.0-py3-none-any.whl.

File metadata

  • Download URL: arlogi-0.608.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for arlogi-0.608.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bac30fc4231c1318d3b5a84cf873d7f6d286a5d63134336c3f28162e3c2c2e7a
MD5 d7f696b071626a61636bb1d7f548c0d6
BLAKE2b-256 16175187705c11d95ae705e5681e90fe2289b71414f8269cc7232a7beeb16bbe

See more details on using hashes here.

Release history Release notifications | RSS feed

0.611.1

2 files

0.610.0

2 files

0.609.0

2 files

This release

0.608.0 This release

2 files

0.601.4

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page