Skip to main content

Time handler for repetitive short-duration processes.

Project description

ATRFileHandler

ATRFileHandler, or AbsoluteTimedRotatingFileHandler, is a file handler like TimedRotatingFileHandler that also caches the next rollover time for your logfiles, allowing future instances of your application to rotate the logfile in schedule, avoiding surprices of large logfiles that haven't rotated as you expected.

Diferences with TimedRotatingFileHandler

The main difference is that instead of only using the handler creation time to calculate the next rollover, it also writes and reads it from a cache file. With TimeRotatingFileHandler, if you want to rotate logs daily but your process starts and ends in a couple of minutes, when you run it in one hour the logfile will not rotate, because the handler won't remember the last time it was used. ATRHandler will rotate it because it saves this data to a file cache.

This allows you to easily keep weekly logfiles for a periodic shot-lived process, without making that process into a service or long running process.

Install

With pip:

pip install ATRFileHandler

Usage

It can be used exactly as the TimedRotatingFileHandler from the builting logging module.

Example:

import logging
from ATRFileHandler import ATRFileHandler

logger = logging.getLogger()
handler = ATRFileHandler("test.log", when="D", interval=3, backupCount=3)
logger.addHandler(handler)
logger.error("too much rythm")

Running tests

pip install -e .
pytest --cov=ATRFileHandler/

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

ATRFileHandler-0.1.1.tar.gz (15.8 kB view hashes)

Uploaded Source

Built Distribution

ATRFileHandler-0.1.1-py3-none-any.whl (15.0 kB view hashes)

Uploaded Python 3

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