Skip to content

Combined python log handler to rotate log files based on both size and time.

Notifications You must be signed in to change notification settings

suraj-arya/chandler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Combined python log handler to rotate log files based on both size and time.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages