DECOLOG
A lightweight Python logging decorator that automatically logs function calls, arguments, execution time, and exceptions. Provides both console and file logging with configurable verbosity.
Installation
pip install decolog
Quick Start
Basic Usage
from decolog import Logger
import logging
# Initialize logger
logger = Logger(
app_name="my_app",
dir_path="./logs",
log_level=logging.DEBUG,
console_handler_level=logging.DEBUG,
file_handler_level=logging.DEBUG
)
# Decorate functions - logs calls automatically
@logger
def add_numbers(a, b):
return a + b
@logger
def greet(name):
return f"Hello, {name}!"
# Function calls are automatically logged
result = add_numbers(5, 3) # Logs: function name, args, execution time
message = greet("World") # Logs: function name, args, execution time
Per-Function Verbosity Control
Control whether function arguments are truncated in logs:
# Default: arguments are truncated (verbose=False)
@logger
def function1(x, y, z):
return x + y + z
# Explicit verbose=False (same as default)
@logger(is_verbose=False)
def function2(x, y, z):
return x + y + z
# Full arguments shown (verbose=True)
@logger(is_verbose=True)
def function3(x, y, z):
return x + y + z
Features
- Automatic function logging: Logs function name, arguments, execution time
- Exception logging: Automatically logs exceptions with traceback
- Dual output: Logs to both console and file
- Per-function verbosity: Control argument display per function
- Configurable log levels: Set different levels for console and file output
- Daily log rotation: Creates new log files daily
Parameters
Logger Initialization
Logger(
app_name: str, # Application name (used in log files)
dir_path: str | Path, # Directory for log files
log_level: int = logging.DEBUG, # Overall log level
console_handler_level: int = logging.DEBUG, # Console log level
file_handler_level: int = logging.DEBUG # File log level
)
Decorator Usage
@logger(is_verbose=False) # Truncate function arguments in logs (default)
@logger(is_verbose=True) # Show full function arguments in logs
Log Format
Logs follow this format:
YYYY-MM-DD HH:MM:SS|app_name|LOG_LEVEL:message
Example log entry:
2023-11-15 14:30:45|my_app|DEBUG:add_numbers(*(5, 3), **{})
2023-11-15 14:30:45|my_app|DEBUG:executed add_numbers(*(5, 3), **{}) in 0.0001 seconds
Advanced Example
from decolog import Logger
import logging
# Configure logger
logger = Logger(
app_name="data_processor",
dir_path="/var/log/myapp",
console_handler_level=logging.INFO, # Less verbose console output
file_handler_level=logging.DEBUG # Detailed file logs
)
# Decorate multiple functions with different verbosity
@logger
def load_data(file_path):
# ... implementation ...
pass
@logger(is_verbose=True)
def process_data(data, config):
# ... implementation ...
pass
@logger(is_verbose=False)
def save_results(results, output_path):
# ... implementation ...
pass
# All function calls are automatically logged
load_data("input.csv")
process_data(data, config={"param": "value"})
save_results(results, "output.json")
Metadata
Release files for decolog 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| decolog-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for decolog-0.1.0-py3-none-any.whl |
Release files / decolog-0.1.0-py3-none-any.whl
| Download URL | decolog-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e7d5dc8332e630aafdcbcc98c73c9077ac163349acffef2ad008a4440830fa39
|
|
BLAKE2b-256 checksum How to use checksums |
c93984cacd755cbe2908404a66e67e13af427249293fc86d53961ebac8410c81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Security for decolog 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.