Skip to main content

TimedRotatingFileHandler using ctime instead of mtime to determine rollover times.

Project description

CTimedRotatingFileHandler

TimedRotatingFileHandler using ctime instead of mtime to determine rollover times.

This module provides a subclass CTimedRotatingFileHandler of logging.handlers.TimedRotatingFileHandler that uses file creation time instead of file modification time to calculate the next rollover time.

It also contains a workaround for "file system tunneling" on Windows, which prevents new files from having new creation times if they have already existed a short time ago.
To be able to do this, a new dependency to win32-setctime is introduced (only needed if running on Windows).

Usage Example

import logging
from ctimed_rotating_file_handler import CTimedRotatingFileHandler

logfile = 'path/to/logdir/MyName.log'
loglevel=logging.DEBUG
backupcount = 7
logformat='%(asctime)s\t%(levelname)s\t%(name)s\t%(message)s'

log = logging.getLogger()
formatter = logging.Formatter(fmt=logformat)
loghandler = CTimedRotatingFileHandler(logfile, when='midnight', interval=1, backupCount=backupcount)
loghandler.setFormatter(formatter)
logging.root.addHandler(loghandler)
logging.root.setLevel(loglevel)

log.info('This is an information.')

Development and building

Prerequesites

  • Python 3.9 has to be installed with pip and packages:
    • virtualenv
    • build

Setup development environment

After cloning the repo, you should create a virtual environment for all further development work.
This may be done by calling one of the included setup_venv scripts for your platform:

  • setup_venv.cmd: Windows batch
  • setup_venv.ps1: Windows Powershell
  • setup_venv.sh: Bash

This will

  • create a new virtual environment in the directory venv or update an existing one,
  • install all requirements from requirements.txt.

You still have to activate the venv manually (or automatically by configuring it in your IDE).

Building the package

All buils settings are inside pyproject.toml.
You might want to change project.version before building (eg. add .dev1 to it), so you always know which one you are dealing with.

To build the project, simply run this command from inside the project directory (the same directory that contains pyproject.toml):

python -m build

This will create .whl and .tar.gz in the directory dist.

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

ctimed_rotating_file_handler-0.1.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ctimed_rotating_file_handler-0.1.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file ctimed_rotating_file_handler-0.1.1.tar.gz.

File metadata

File hashes

Hashes for ctimed_rotating_file_handler-0.1.1.tar.gz
Algorithm Hash digest
SHA256 18c06acfbc6ada3d4b204758ef73b4e178352ef06afeabf9bdee5f13ec4d26d6
MD5 14fbff52cf69a9d01564ac07f4c7163e
BLAKE2b-256 89d243b8cea734b800f126b4e1fb968aeb8630245e5d8a6d477551ddee91b091

See more details on using hashes here.

File details

Details for the file ctimed_rotating_file_handler-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ctimed_rotating_file_handler-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 af1f2dfbb4f4df95d3fa7315d2f4678ade56013e9bc011ea8f2ce00c22fe43b6
MD5 86ee06f5330a90a5f00b2c6ee54b72ba
BLAKE2b-256 5d65570e3413e8664eaf98ea855c98950f02bed1db1667b0969b309c7f6bb35b

See more details on using hashes here.

Supported by

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