Skip to main content

TimedRotatingFileHandler using ctime instead of mtime to determine rollover times.

Project description

CTimedRotatingFileHandler

TimedRotatingFileHandler for python logging, that uses ctime instead of mtime to determine rollover times.

This module provides CTimedRotatingFileHandler as a subclass of logging.handlers.TimedRotatingFileHandler. It 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'

logger = 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)

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

Development and building

Prerequesites

This project uses uv for development, build and deploy, so uv has to be installed and must be found on the system PATH.

All project settings can be found in pyproject.toml.

Setup development environment

After cloning the repo, run uv sync once to set up a venv with all dependencies in the directory .venv.

Building the package

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

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

uv build

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

Deployment

Before deploying to pypi.org or test.pypi.org, make sure the correct new version is entered in pyproject.toml.

Delete the dist folder and build the latest version so only this version is present (uv will try to upload all versions it can find in the folder).

Test-Release on https://test.pypi.org

  • Set the environment variable UV_PUBLISH_TOKEN to a test.pypi.org-token with privileges for this project.
  • Call uv publish with publish-url set to https://test.pypi.org/legacy/

Windows:

$env:UV_PUBLISH_TOKEN = "pypi-..."
uv publish --publish-url https://test.pypi.org/legacy/

Linux

export UV_PUBLISH_TOKEN="pypi-..."
uv publish --publish-url https://test.pypi.org/legacy/ 

Release on https://pypi.org

  • Set the environment variable UV_PUBLISH_TOKEN to a pypi.org-token with privileges for this project.
  • Call uv publish with no additional arguments

Windows:

$env:UV_PUBLISH_TOKEN = "pypi-..."
uv publish

Linux

export UV_PUBLISH_TOKEN="pypi-..."
uv publish 

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.2.0.tar.gz (5.7 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.2.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ctimed_rotating_file_handler-0.2.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.22 {"installer":{"name":"uv","version":"0.11.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ctimed_rotating_file_handler-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f99852b45fdd98aeb6051c8aa4bcb5ffacd3afab1cdccbdefebed171dd451076
MD5 025c429836013adbe3042ab542fbb79a
BLAKE2b-256 e516efcbc8bd834379e191580d328db5fd65ed3734f051e10752e75c5a5982d0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ctimed_rotating_file_handler-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.22 {"installer":{"name":"uv","version":"0.11.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ctimed_rotating_file_handler-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b66ba514693014f01f7c753d0e129cbc7822ca92777702059a5c6a0bed306a1
MD5 3acc4f5737e09cc9ca1a301007dcc807
BLAKE2b-256 24e33758ea460250c2241fcdff0a3dc63dd13f5379f68396d25369c14f7b0945

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