Skip to main content

Advanced Python Logging

Project description

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.10+

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.
  • 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.

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.')

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
)

Mirrors: acid.vegasSuperNETsGitHubGitLabCodeberg

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

apv-4.0.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

apv-4.0.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file apv-4.0.0.tar.gz.

File metadata

  • Download URL: apv-4.0.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.3

File hashes

Hashes for apv-4.0.0.tar.gz
Algorithm Hash digest
SHA256 72a6bdc4aadb5036d73b56ccd7c01b4a5df8479b95059501be57eba79a12e840
MD5 e766a3215cccc58d8bc2cd3f0dc885e8
BLAKE2b-256 e42378839e828deafff606806f09f8de498262fbfb4de3c377b6be0884c76167

See more details on using hashes here.

File details

Details for the file apv-4.0.0-py3-none-any.whl.

File metadata

  • Download URL: apv-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.3

File hashes

Hashes for apv-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e9a82e2f94b61c53d420187cd78d6ea3846cbd95e161edd2c5ed9b19cd05387
MD5 52d6432a17db458375be64ee8ca321b9
BLAKE2b-256 1c4fa0474047d8a8c4babfeef543e8b05c3541b2753ccf1687bfe88290e34ef6

See more details on using hashes here.

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