Skip to main content

Concurrent logging handler (drop-in replacement for RotatingFileHandler)

Project description

Overview

This module provides an additional log handler for Python’s standard logging package (PEP 282). This handler will write a log entries to a set of files, which switches from one file to the next when the current file reaches a certain size. Multiple processes can write to the log file concurrently.

Details

The ConcurrentRotatingFileHandler class is a drop-in replacement for Python’s standard log handler RotatingFileHandler. This module uses file locking so that multiple processes can concurrently log to a single file without dropping or clobbering log records. This module provides a file rotation scheme like RotatingFileHanler, except that extra care is taken to ensure that logs can be safely rotated before the rotation process is started. (This module works around the file rename issue with RotatingFileHandler on Windows, where a rotation failure means that all subsequent logs are lost).

This module’s attempts to preserve log records at all cost. This means that log files will grow larger than the specified maximum (rotation) size. So if disk space is tight, you may want to stick with RotatingFileHandler, which will strictly adhere to the maximum file size.

Installation

Use the following command to install this package:

easy_install ConcurrentLogHandler

Simple example

Here is a example demonstrating how to use this module:

from logging import getLogger, INFO
from cloghandler import ConcurrentRotatingFileHandler
import os

log = getLogger()
# Use an absolute path to prevent file rotation trouble.
logfile = os.path.abspath("mylogfile.log")
# Rotate log after reaching 512K, keep 5 old copies.
rotateHandler = ConcurrentRotatingFileHandler(logfile, "a", 512*1024, 5)
log.addHandler(rotateHandler)
log.setLevel(INFO)

log.info("Here is a very exciting log message, just for you")

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

ConcurrentLogHandler-0.7.3.tar.gz (18.1 kB view hashes)

Uploaded Source

Built Distributions

ConcurrentLogHandler-0.7.3-py2.5.egg (23.3 kB view hashes)

Uploaded Source

ConcurrentLogHandler-0.7.3-py2.4.egg (23.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page