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.
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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1faeed741ab00935674aee5540deab778dcaa4114197ac073318a958feb1864b
|
|
| MD5 |
0c1f1eeafe2f488f1f3e71cd73064f79
|
|
| BLAKE2b-256 |
0e35bc3a57f2fdb1c8ebc072f0b7ecaa3b8523e2bf98ee5c48590c4de178db82
|
Provenance
The following attestation bundles were made for uvulog-1.0.4.tar.gz:
Publisher:
publish.yml on lupnis/uvulog
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
uvulog-1.0.4.tar.gz -
Subject digest:
1faeed741ab00935674aee5540deab778dcaa4114197ac073318a958feb1864b - Sigstore transparency entry: 529080370
- Sigstore integration time:
-
Permalink:
lupnis/uvulog@3ff32e11bf69f781a6bebb84314e123315a033a6 -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/lupnis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3ff32e11bf69f781a6bebb84314e123315a033a6 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bdbb01efbf5e1ff8cdd3f53f2063dcbc48178302d7099cc01b6cadd7010b6d9
|
|
| MD5 |
c149303c081d65c1ebd5fd0f64883ad9
|
|
| BLAKE2b-256 |
f4fc7c3bd9f88cef1d436f79b52bbb44fd8d766c88d567e2964b18037b03a058
|
Provenance
The following attestation bundles were made for uvulog-1.0.4-py3-none-any.whl:
Publisher:
publish.yml on lupnis/uvulog
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
uvulog-1.0.4-py3-none-any.whl -
Subject digest:
7bdbb01efbf5e1ff8cdd3f53f2063dcbc48178302d7099cc01b6cadd7010b6d9 - Sigstore transparency entry: 529080379
- Sigstore integration time:
-
Permalink:
lupnis/uvulog@3ff32e11bf69f781a6bebb84314e123315a033a6 -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/lupnis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3ff32e11bf69f781a6bebb84314e123315a033a6 -
Trigger Event:
push
-
Statement type: