Skip to main content

BruteLogger

A brutish file logger for when you just need to tee your screen. Forks stdout to multiple handlers.

Notice

Logging done right should use logging, or the wonderful loguru.

Installation

pip install brutelogger

Usage

from brutelogger import BruteLogger
BruteLogger.save_stdout_to_file()
# Everything on screen from now on will be copied
# to a timestamped file inside `./logs/`

More options:

from brutelogger import BruteLogger
BruteLogger.save_stdout_to_file(path='captains_log', fname='stardate_41153.7',
                                mode='wb', encoding='utf8', also_stderr=True)
print("Our destination is planet Deneb IV")
# => outputs both to terminal and to file `captains_log/stardate_41153.7` (in binary)

See the implementation of save_stdout_to_file for advanced usage.

Applications

This library offers instead a brute redirect of everything that comes on screen to multiple handlers, typically including the original terminal and a log file. The goal is to maintain a hard copy of the output in case of failure, or for future processing.

For example, the original use case included multiple processes running asynchronously, each calling a C library which used printf() to deliver important algorithm statistics. These became easy to retrieve from the log file using regular expressions.

How does it work

Any function (call, message) on (/to) the object is propagated verbatim with parameters to each and all handlers. For example, calling BruteLogger.save_stdout_to_file() such as calling sys.stdout.flush() after using This means that a call to sys.stdout.flush() will translate in calling flush() on both the terminal file handler and on the opened log file handler. Same goes for example with close() being called upon program termination.

Todo

  • Option to switch back sys.__stdout__
  • Add / remove handlers
  • Accessing handlers (e.g. calling close() only on the file log, not on the __stdout__)

Metadata

Release files for brutelogger 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for brutelogger 0.1.2
File Size Uploaded Provenance Actions
brutelogger-0.1.2.tar.gz 3.3 kB Without provenance Details for brutelogger-0.1.2.tar.gz

Release files / brutelogger-0.1.2.tar.gz

Download URL brutelogger-0.1.2.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2911fd4f80b4057b8bcdae59e3dd26ac24fd46b2a62e4fa72e634e893c047225
BLAKE2b-256 checksum
How to use checksums
34a4678345de1bb49536eab9431269fbdd5c5cc7316702e7b6438206fd3f1f73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

Security for brutelogger 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.2 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page