Skip to main content

A brutish file logger for when you just need to `tee` your screen.

Project description

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__)

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

brutelogger-0.1.2.tar.gz (3.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page