Skip to main content

A simple logger for console and file logging, with colored output and log rotation.

Project description

uvulog

A simple logger for console and file logging, with colored output and log rotation.

human-coded llm-documents

Features

  • Colored terminal output: ANSI color support, log levels highlighted.
  • File log rotation: Automatic log file splitting, with cache and size/line limits.
  • Extensible render blocks: Pluggable blocks for time, process ID, counters, source file, line number, etc.
  • Process safety: Safe writing in multi-process/multi-threaded environments, with file locking.
  • High performance: Memory buffering, batch writes, optimized for low overhead.
  • User-friendly API: Easy integration, shortcut methods (info, debug, error, etc.).

Quick Start

from uvulog import Logger, Styled, Styles

logger = Logger()
logger.info(Styled("Hello uvulog!", Styles.GREEN, Styles.BOLD))
logger.error(Styled("Something went wrong!", Styles.RED, Styles.UNDERLINE))

Log Levels

  • TRACE
  • DEBUG
  • INFO
  • NOTICE
  • WARNING
  • ERROR
  • CRITICAL

Each level supports custom styles and formatting.

File Log Rotation

  • Automatically splits log files by size or line count
  • Supports line caching to reduce disk IO
  • Safe file locking to prevent concurrent write conflicts

There is no config to directly enable/disable rotation. To enable this feature, you should add {rotate_count}, {date} or other enabled keys in blocks to file.save_config.file_name_fmt

Render Block Examples

  • Timestamp [2025-09-17 12:00:00]
  • Log level INFO
  • Main message content
  • Process ID, counter, source file, line number, etc.

Installation

pip install uvulog

Configuration Guide

You can fully customize uvulog using a configuration dictionary when creating a Logger instance.
Below is a detailed example and explanation of each option:

from uvulog import Logger, Levels

custom_config = {
    "logger_name": "myapp",
    "console": {
        "enabled": True,                # Enable console output
        "colored": True,                # Use ANSI colors in terminal
        "level": Levels.DEBUG,          # Minimum log level for console
        "text_fmt": "{time}{level}{main}\n",  # Output format
        "blocks_config": {              # Customize render blocks
            "time": {
                "args": [
                    ["[", 90],          # Bright black
                    ["{}", 97],         # Bright white
                    ["]", 90]
                ],
                "kwargs": {
                    "time_format": "%H:%M:%S"
                }
            },
            "level": {
                "args": [["{}"]],
                "kwargs": {
                    "levels": {
                        Levels.INFO: [[" I ", 37]],      # White
                        Levels.ERROR: [[" E ", 41, 30]]  # Red background, black text
                    }
                }
            },
            "main": {
                "args": [["{}"]],
                "kwargs": {
                    "levels": {
                        Levels.INFO: [["{}", 37]],
                        Levels.ERROR: [["{}", 91]]       # Bright red
                    }
                }
            }
        }
    },
    "file": {
        "enabled": True,                # Enable file logging
        "colored": False,               # No ANSI colors in file
        "save_config": {
            "root_dir": "logs",         # Log directory
            "file_name_fmt": "myapp.log", # Log file name
            "cache_lines": 100,         # Buffer lines before writing
            "max_lines": 10000,         # Max lines per file
            "max_size": 10 * 1024 * 1024 # Max size per file (bytes)
        },
        "level": Levels.INFO,           # Minimum log level for file
        "text_fmt": "{time}{level}{main}\n",
        "blocks_config": None           # Use default if None
    }
}

logger = Logger(config=custom_config)

Configuration Options

  • logger_name: Name of the logger, used in output.
  • console.enabled: Enable/disable console output.
  • console.colored: Use colored output in terminal.
  • console.level: Minimum log level for console output.
  • console.text_fmt: Format string for each log line.
  • console.blocks_config: Dict to customize each block (time, level, main, etc.).
  • file.enabled: Enable/disable file logging.
  • file.colored: Use colored output in log files.
  • file.save_config.root_dir: Directory to save log files.
  • file.save_config.file_name_fmt: Log file name format.
  • file.save_config.cache_lines: Number of lines to buffer before writing.
  • file.save_config.max_lines: Maximum lines per log file.
  • file.save_config.max_size: Maximum size per log file (in bytes).
  • file.level: Minimum log level for file output.
  • file.text_fmt: Format string for file log lines.
  • file.blocks_config: Dict to customize blocks for file output.

You can override any block (such as time, level, main) with your own style and format.


Use Cases

  • Suitable for AI, data science, web backend, CLI tools, and all Python projects
  • Supports multi-process/multi-threaded environments
  • Compatible with Linux, Mac, and Windows

License

MIT

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

uvulog-1.0.4.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

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

uvulog-1.0.4-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file uvulog-1.0.4.tar.gz.

File metadata

  • Download URL: uvulog-1.0.4.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for uvulog-1.0.4.tar.gz
Algorithm Hash digest
SHA256 1faeed741ab00935674aee5540deab778dcaa4114197ac073318a958feb1864b
MD5 0c1f1eeafe2f488f1f3e71cd73064f79
BLAKE2b-256 0e35bc3a57f2fdb1c8ebc072f0b7ecaa3b8523e2bf98ee5c48590c4de178db82

See more details on using hashes here.

Provenance

The following attestation bundles were made for uvulog-1.0.4.tar.gz:

Publisher: publish.yml on lupnis/uvulog

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

File details

Details for the file uvulog-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: uvulog-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for uvulog-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7bdbb01efbf5e1ff8cdd3f53f2063dcbc48178302d7099cc01b6cadd7010b6d9
MD5 c149303c081d65c1ebd5fd0f64883ad9
BLAKE2b-256 f4fc7c3bd9f88cef1d436f79b52bbb44fd8d766c88d567e2964b18037b03a058

See more details on using hashes here.

Provenance

The following attestation bundles were made for uvulog-1.0.4-py3-none-any.whl:

Publisher: publish.yml on lupnis/uvulog

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