Advanced Python Logging (APV)
Flexible & powerful logging solution for Python applications
Table of Contents
Introduction
APV emerged from a simple observation: despite the abundance of logging solutions, there's a glaring lack of standardization in application logging. APV is my response to this challenge – a logging library that doesn't aim to revolutionize the field, but rather to streamline it.
Requirements
- Python 3
Installation
From PyPI
pip install apv
From Source
git clone https://github.com/acidvegas/apv
cd apv
pip install .
Features
- Console Logging with Colors: Enhanced readability with colored log messages in the console.
- File Logging: Write logs to files with support for log rotation based on size and number of backups.
- Log Compression: Automatically compress old log files using gzip to save disk space.
- JSON Logging: Output logs in JSON format for better structure and integration with log management systems.
- Syslog Capabilities: Out logs (optionally in JSON) to the machines syslog.
- Detailed Log Messages: Option to include module name, function name, and line number in log messages.
Configuration Options
The setup_logging function accepts the following keyword arguments to customize logging behavior:
| Name | Default | Description |
|---|---|---|
level |
INFO |
The logging level. (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
date_format |
'%Y-%m-%d %H:%M:%S' |
The date format for log messages. |
log_to_disk |
False |
Whether to log to disk. |
max_log_size |
10*1024*1024 (10 MB) |
The maximum size of log files before rotation (in bytes). |
max_backups |
7 |
The maximum number of backup log files to keep. |
log_file_name |
'app' |
The base name of the log file. |
json_log |
False |
Whether to log in JSON format. |
show_details |
False |
Whether to include module name, function name, & line number in log messages. |
compress_backups |
False |
Whether to compress old log files using gzip. |
syslog |
False |
Whether to send logs to syslog. |
Usage
Basic Console Logging
import logging
import apv
# Set up basic console logging
apv.setup_logging(level='INFO')
logging.info('This is an info message.')
logging.error('This is an error message.')
Console Logging with Details
import logging
import apv
# Set up console logging with detailed information
apv.setup_logging(level='DEBUG', show_details=True)
logging.debug('Debug message with details.')
File Logging with Rotation
import logging
import apv
# Set up file logging with log rotation
apv.setup_logging(
level='INFO',
log_to_disk=True,
max_log_size=10*1024*1024, # 10 MB
max_backups=5,
log_file_name='application_log'
)
logging.info('This message will be logged to a file.')
File Logging with Compression and JSON Format
import logging
import apv
# Set up file logging with compression and JSON format
apv.setup_logging(
level='DEBUG',
log_to_disk=True,
max_log_size=5*1024*1024, # 5 MB
max_backups=7,
log_file_name='json_log',
json_log=True,
compress_backups=True
)
logging.debug('This is a debug message in JSON format.')
Syslog Logging
import logging
import apv
# Set up syslog logging
apv.setup_logging(level='INFO', syslog=True)
logging.info('This message will be sent to syslog.')
logging.error('Error messages are also sent to syslog.')
Syslog Logging with JSON Format
import logging
import apv
# Set up syslog logging with JSON format
apv.setup_logging(level='DEBUG', syslog=True, json_log=True)
logging.debug('This debug message will be sent to syslog in JSON format.')
logging.info('Info messages are also sent as JSON to syslog.')
Syslog Logging with Details
import logging
import apv
# Set up syslog logging with detailed information
apv.setup_logging(level='DEBUG', syslog=True, show_details=True)
logging.debug('This debug message will include module, function, and line details in syslog.')
Mixing it all together
import logging
import apv
# Set up logging to all handlers
apv.setup_logging(
level='DEBUG',
log_to_disk=True,
max_log_size=10*1024*1024,
max_backups=7,
log_file_name='app',
json_log=True,
compress_backups=True,
show_details=True,
syslog=True
)
Mirrors: acid.vegas • SuperNETs • GitHub • GitLab • Codeberg
Metadata
Release files for apv 4.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| apv-4.2.2.tar.gz | 6.6 kB | Without provenance | Details for apv-4.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| apv-4.2.2-py3-none-any.whl | Python 3 | none | any | Details for apv-4.2.2-py3-none-any.whl |
Total release size: 13.3 kB
Release files / apv-4.2.2.tar.gz
| Download URL | apv-4.2.2.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f17b06dfc0803cd0c4fff5b314957f229beddca48ac09a4bbf709742476f2fa
|
|
BLAKE2b-256 checksum How to use checksums |
fc09b315e88e5ea6691382895fd22c90b422e1721949de5dac5cfca1fccdd23f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|
Release files / apv-4.2.2-py3-none-any.whl
| Download URL | apv-4.2.2-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d20805405c2db45aa6a39ec270203596388cc8cb8120c43b71626379398196ca
|
|
BLAKE2b-256 checksum How to use checksums |
4c81811b8ae8e142812d031a770c8657e9c5f4fc43745d0ba0311da934e72cd3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|
Security for apv 4.2.2
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.