Skip to main content

A ZERO dependency rotating file handler which rotates when YOU want it to, rather than based on bytes size.

Project description

Rotate Text File

A rotating file handler which rotates when YOU want it to, rather than based on bytes size.

When to use this module?

  • When you have that niche case of logs being written into some text file from several functions and you just want it to rotate without having to re-write all the write calls with some new package.

Why not use RotatingFileHandler provided by Python's logging module?

  • If you are thinking of logging, please use RotatingFileHandler. It provides doRollover method which does the same functionality but with all the logging APIs.
  • This module aims to solve cases of code where outputs were just being dumped into some file and over time the code grew so big that rotating the text file was needed without distrubing/refactoring the entire codebase.

Installation

coming soon on pip

Usage:

  • Any existing code with text file can be replaced with the RotateTextFile constructor and a checker function.
  • Eg:

If you have some code like:

with open("path/to/text/file","w") as fp:
  fp.write("some log")

All you have to do is:

def condition():
  return some_variable==0

with RotateTextFile("path/to/text/file",condition,10) as fp: #10 is backupCount as in RotatingFileHandler
  fp.write("some log")
  • condition is called on every write. You can think of it as an analogy to a sort function which takes your checking function as an input.
  • RotateTextFile inherits io.TextIOWrapper, so to pass any arguments specific to io.TextIOWrapper's constructor, just pass them as Keyword Arguments.
  • Since a file is rotated only on write, RotateTextFile constructor opens the file in ab+ mode. Other supported modes are :wb. mode can be passed as: RotateTextFile("path/to/text/file",condition,10,'wb'):
  • backupCount indicates how many backups a file can have before it is rotated.
  • Like RotatingFileHandler provided by Python's logging module, RotateTextFile guarentees that the file being written to will ALWAYS be filename.log

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

RotatingTextFile-0.0.1.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

RotatingTextFile-0.0.1-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file RotatingTextFile-0.0.1.tar.gz.

File metadata

  • Download URL: RotatingTextFile-0.0.1.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for RotatingTextFile-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b99334891900a8d66532212212270dd56465342e00c362b45efb9a2cc2613949
MD5 70ede0ac716e546679ad79e370fddc78
BLAKE2b-256 6a5cd3d473155c964ef2ccf14c0a8327ff4387adb1039604b9dbe18b0331f400

See more details on using hashes here.

File details

Details for the file RotatingTextFile-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: RotatingTextFile-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for RotatingTextFile-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5f805416ef24aa2f830776a1ad04a33577f9ff81b593ce95c5b48c332493437c
MD5 d17aa49450e7013b738e87acf720ef01
BLAKE2b-256 9251fe57c176b66e58e52b250abd499fa339967ae64a0c72db0216617b5d4787

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