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.
Installation
pip install RotatingTextFile
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")
conditionis called on every write. You can think of it as an analogy to a sort function which takes yourcheckingfunction as an input.RotateTextFileinheritsio.TextIOWrapper, so to pass any arguments specific toio.TextIOWrapper's constructor, just pass them as Keyword Arguments.- Since a file is rotated only on write,
RotateTextFileconstructor opens the file inab+mode. Other supported modes are :wb.modecan be passed as:RotateTextFile("path/to/text/file",condition,10,'wb'): backupCountindicates how many backups a file can have before it is rotated.- Like
RotatingFileHandlerprovided by Python's logging module,RotateTextFileguarentees that the file being written to will ALWAYS befilename.log
Metadata
Release files for RotatingTextFile 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| RotatingTextFile-0.0.2.tar.gz | 2.9 kB | Without provenance | Details for RotatingTextFile-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| RotatingTextFile-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for RotatingTextFile-0.0.2-py3-none-any.whl |
Total release size: 18.2 kB
Release files / RotatingTextFile-0.0.2.tar.gz
| Download URL | RotatingTextFile-0.0.2.tar.gz |
|---|---|
| Size | 2.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cc4fc829860b7934d79d6fcb8d8b91e9df86e5f76e9ecc231e3bee3c140a45e3
|
|
BLAKE2b-256 checksum How to use checksums |
c5e4c42b44a7778dac9d090f95e9d6a4e29536e571fe2699e8f2d3168f5c4010
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / RotatingTextFile-0.0.2-py3-none-any.whl
| Download URL | RotatingTextFile-0.0.2-py3-none-any.whl |
|---|---|
| Size | 15.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a3b898045a6fe8e5dfbae996f0878e3be9398e2b7705fae182782bed89c9adf5
|
|
BLAKE2b-256 checksum How to use checksums |
0cdf27f28101fffc70d5084cdb8e65233bd20e984d65724ee6c30cc5d93aa851
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for RotatingTextFile 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.