Skip to main content

By this command line tool, you can run a python repl which logs everying into a file.

Project description

Usage

Install:

pip install logrepl

run the repl:

pylogrepl

then the whole repl will be logged to the file yyyymmddhhmm.log.

You can also use logrepl to log the whole stream io of a program by:

import logrepl
with logrepl.log_handler(
    log_dir,
    prefix,
    err_acc_time
) as logrepl_handler:
    # run your program here
    # ...

Config

Prefix of the log file

use the optional positional argument, for example:

pylogrepl prefix

then the log file will be prefix_yyyymmddhhmm.log.

Dir to save the logs

use the -d or --dir options:

pylogrepl -d "store/logs"
pylogrepl --dir "store/logs"

then the log file will be in the store/logs directory.

Time interval to collect errors of logrepl

We found that if something goes wrong in logrepl, it may produce many highly repeatitive exceptions is a short time. To avoid getting overwhelmed by those error messages, logrepl will collect them in a time interval and then print the non-duplicated ones. To set the time interval (although it should be non-necessary), use the '-t' or '--time' options:

pylogrepl -t 1.5
pylogrepl --time 1.5

the unit is in second.

By .pylogrepl file

You can also sepcify the prefix & the directory by making a .pylogrepl in the working directory:

dir=logs
prefix=my_prefix
err_acc_time=1.5

note that the command line arguments are prioritized over the settings in .pylogrepl. We recommend such an approach:

  • specifying dir in .pylogrepl.
  • specifying prefix by command line argument

since you may want to change the prefix frequently but not the dir.

APIs

By executing pylogrepl, the logrepl_handler of class logrepl.Handler will be loaded to the current namespace. The logrepl_handler controls the logging behavior of the repl.

update logging dir / file

logrepl.Handler.set_dir(log_dir)

Update new logging dir. log_dir must be string or Path. The suffix _yyyymmddhhmm.log will also be updated while the prefix will remain unchanged.

logrepl.Handler.set_prefix(prefix)

Update new prefix for the log file. prefix sholud be str or None. The suffix _yyyymmddhhmm.log will also be updated while the log_dir will remain unchanged. Drop the prefix of new log file by setting prefix as None.

logrepl.Handler.update_suffix()

Update the timestamp suffix with log_dir & prefix unchanged.

start / stop logging to file

logrepl.Handler.start_log()

Start logging to the file.

logrepl.Handler.stop_log()

Stop logging to the file.

handle sys.stdin/stdout/stderr & builtins.input

logrepl.Handler.set_io()

To log everything of the repl, logrepl modifies sys.stdin/stdout/stderr & builtins.input by this method.

logrepl.Handler.reset_io()

Reset sys.stdin/stdout/stderr & builtins.input as-is. The input to the repl wil stil be logged into the file after executing reset_io.

Notes

Exceptions ocurred when writing to the log file will not be logged since it'll lead to infinite loop.

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

logrepl-0.2.3.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

logrepl-0.2.3-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file logrepl-0.2.3.tar.gz.

File metadata

  • Download URL: logrepl-0.2.3.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/5.15.146.1-microsoft-standard-WSL2

File hashes

Hashes for logrepl-0.2.3.tar.gz
Algorithm Hash digest
SHA256 24921754e5af4a2834497a41c6c8d6a721c78de5b379159148d45fec49b73069
MD5 bddedad0f04fe53fb70bd0c950244f5f
BLAKE2b-256 b84913641263f6e5d7f734909fed00a4e876019b2587b6952dc52f193c464453

See more details on using hashes here.

File details

Details for the file logrepl-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: logrepl-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.7 Linux/5.15.146.1-microsoft-standard-WSL2

File hashes

Hashes for logrepl-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ae0b5563ff81235b56a79dfc41677d4c22ad723bb8f73b4eadf03f689020e52e
MD5 77d1fc3f269a0bda055ddbc6210a2644
BLAKE2b-256 5fbc0b938bb4d0c53f14b0e1a7d3d97ca997030ba6e09f9a94641785b8aff86f

See more details on using hashes here.

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