Skip to main content

Python Size and Time Based Logging File Rotating Handler

Python logging's file based handlers have two different kinds of rotation.

However, these rotations work in isolation. Only one handler can be attached to a log file. One can only add either Size based rotation or Time based rotation.

Using chandler.handler.SizedAndTimedRotatingHandler you can rotate the files based on both time and size. Files will be rotated whenever either of the conditions are met.

How to Use

import the handler

from chandler.handler import SizedAndTimedRotatingHandler

Then you can initialise your loggers and append this handler.

logger = logging.getLogger('test-logger')
log_file_path = '/var/log/test/logging.log'
rotating_handler = SizedAndTimedRotatingHandler(log_file_path, when='h', interval=1, max_bytes=50000, backup_count=3)
logger.addHandler(rotating_handler)

In the above example the handler is configured to rotate every one hour or whenever the file size reaches 50k bytes. This handler is built on top of TimedRotatingFileHandler, so most of the arguments are similar to that of TimedRotatingFileHandler.

installation

You can install with pip

$ pip install chandler-handler

Contribution

Authors

Metadata

Release files for chandler-handler 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chandler-handler 0.0.2
File Size Uploaded
chandler-handler-0.0.2.tar.gz 7.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chandler-handler 0.0.2
File Interpreter ABI Platform
chandler_handler-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 12.0 kB

Release files / chandler-handler-0.0.2.tar.gz

Download URL chandler-handler-0.0.2.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d84e3c37c82a1e017662f2ef4c7d4a2f95cffc52fcc8755dde69ea5b866fb784
BLAKE2b-256 checksum
How to use checksums
d2546f7985b193ecd7ae09f2c3d871275d0d476e310f835193039bd962d78b31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.10

Release files / chandler_handler-0.0.2-py3-none-any.whl

Download URL chandler_handler-0.0.2-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
484efe84435fdf9f7e7ed45b5f0c0ea36731209d1eecb372840cd8ae3ae170d0
BLAKE2b-256 checksum
How to use checksums
5452cbfcf094b51af7e880d8ca3424b220ae8077f84c3e5c580bdf124f326af9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.10

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page