Skip to main content

Python Size and Time Based Logging File Rotating Handler

Project description

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

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

chandler-handler-0.0.2.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

chandler_handler-0.0.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file chandler-handler-0.0.2.tar.gz.

File metadata

  • Download URL: chandler-handler-0.0.2.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.10

File hashes

Hashes for chandler-handler-0.0.2.tar.gz
Algorithm Hash digest
SHA256 d84e3c37c82a1e017662f2ef4c7d4a2f95cffc52fcc8755dde69ea5b866fb784
MD5 0f4f23dcc34100629f795cfb8099032e
BLAKE2b-256 d2546f7985b193ecd7ae09f2c3d871275d0d476e310f835193039bd962d78b31

See more details on using hashes here.

File details

Details for the file chandler_handler-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for chandler_handler-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 484efe84435fdf9f7e7ed45b5f0c0ea36731209d1eecb372840cd8ae3ae170d0
MD5 814ec4769dce3a6b34081fe0dcdd54e3
BLAKE2b-256 5452cbfcf094b51af7e880d8ca3424b220ae8077f84c3e5c580bdf124f326af9

See more details on using hashes here.

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