A ZERO dependency rotating file handler which rotates when YOU want it to, rather than based on bytes size.
Rotating 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.
pip install RotatingTextFile
- Any existing code with text file can be replaced with the RotateTextFile constructor and a checker function.
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")
conditionis called on every write. You can think of it as an analogy to a sort function which takes your
checkingfunction as an input.
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,
RotateTextFileconstructor opens the file in
ab+mode. Other supported modes are :
modecan be passed as:
backupCountindicates how many backups a file can have before it is rotated.
RotatingFileHandlerprovided by Python's logging module,
RotateTextFileguarentees that the file being written to will ALWAYS be
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size RotatingTextFile-0.0.2-py3-none-any.whl (15.3 kB)||File type Wheel||Python version py3||Upload date||Hashes View hashes|
|Filename, size RotatingTextFile-0.0.2.tar.gz (2.9 kB)||File type Source||Python version None||Upload date||Hashes View hashes|
Hashes for RotatingTextFile-0.0.2-py3-none-any.whl