logrepl


Namelogrepl JSON
Version 0.2.5 PyPI version JSON
download
home_pagehttps://github.com/baliuzeger/logrepl
SummaryBy this command line tool, you can run a python repl which logs everying into a file.
upload_time2024-04-12 06:31:45
maintainerNone
docs_urlNone
authorbali
requires_python<4.0,>=3.6
licenseNone
keywords repl log logging
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```python
import logrepl
with logrepl.log_handler(
    log_dir,
    prefix,
    err_acc_time
) as logrepl_handler:
    # import modules and packages
    # run your program here
    # ...
```

Beware that you have to import all the modules and packages in the `with` clause. If a logger of some module or package is initialized before the `with` clause, `logrepl` cannot modify its `logging.StreamHandler`, then all the iniformation directed to that `StreamHandler` will not be logged.

# 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.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/baliuzeger/logrepl",
    "name": "logrepl",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.6",
    "maintainer_email": null,
    "keywords": "repl, log, logging",
    "author": "bali",
    "author_email": "baluzeger@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d9/6b/9d14e3c6c43826071edf5a593a6d7d1b47b8d2f1e09d28a78302db8c1fea/logrepl-0.2.5.tar.gz",
    "platform": null,
    "description": "# Usage\nInstall:\n```\npip install logrepl\n```\n\nrun the repl:\n```\npylogrepl\n```\n\nthen the whole repl will be logged to the file `yyyymmddhhmm.log`.\n\nYou can also use `logrepl` to log the whole stream io of a program by:\n\n```python\nimport logrepl\nwith logrepl.log_handler(\n    log_dir,\n    prefix,\n    err_acc_time\n) as logrepl_handler:\n    # import modules and packages\n    # run your program here\n    # ...\n```\n\nBeware that you have to import all the modules and packages in the `with` clause. If a logger of some module or package is initialized before the `with` clause, `logrepl` cannot modify its `logging.StreamHandler`, then all the iniformation directed to that `StreamHandler` will not be logged.\n\n# Config\n\n## Prefix of the log file\n\nuse the optional positional argument, for example:\n```\npylogrepl prefix\n```\n\nthen the log file will be `prefix_yyyymmddhhmm.log`.\n\n## Dir to save the logs\n\nuse the `-d` or `--dir` options:\n```\npylogrepl -d \"store/logs\"\npylogrepl --dir \"store/logs\"\n```\n\nthen the log file will be in the `store/logs` directory.\n\n## Time interval to collect errors of logrepl\n\nWe 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:\n\n```\npylogrepl -t 1.5\npylogrepl --time 1.5\n```\n\nthe unit is in second.\n\n## By .pylogrepl file\n\nYou can also sepcify the prefix & the directory by making a `.pylogrepl` in the working directory:\n\n```\ndir=logs\nprefix=my_prefix\nerr_acc_time=1.5\n```\n\nnote that the command line arguments are prioritized over the settings in `.pylogrepl`. We recommend such an approach:\n\n- specifying `dir` in `.pylogrepl`.\n- specifying `prefix` by command line argument\n\nsince you may want to change the `prefix` frequently but not the `dir`.\n\n# APIs\n\nBy 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.\n\n## update logging dir / file\n\n**logrepl.Handler.set_dir(log_dir)**\n\nUpdate new logging dir. `log_dir` must be `string` or `Path`. The suffix `_yyyymmddhhmm.log` will also be updated while the `prefix` will remain unchanged.\n\n**logrepl.Handler.set_prefix(prefix)**\n\nUpdate 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`.\n\n**logrepl.Handler.update_suffix()**\n\nUpdate the timestamp suffix with `log_dir` & `prefix` unchanged.\n\n## start / stop logging to file\n\n**logrepl.Handler.start_log()**\n\nStart logging to the file.\n\n**logrepl.Handler.stop_log()**\n\nStop logging to the file.\n\n## handle sys.stdin/stdout/stderr & builtins.input\n\n**logrepl.Handler.set_io()**\n\nTo log **everything** of the repl, `logrepl` modifies `sys.stdin/stdout/stderr` & `builtins.input` by this method.\n\n**logrepl.Handler.reset_io()**\n\nReset `sys.stdin/stdout/stderr` & `builtins.input` as-is. The input to the repl wil stil be logged into the file after executing `reset_io`.\n\n# Notes\n\nExceptions ocurred when writing to the log file will not be logged since it'll lead to infinite loop.\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "By this command line tool, you can run a python repl which logs everying into a file.",
    "version": "0.2.5",
    "project_urls": {
        "Homepage": "https://github.com/baliuzeger/logrepl",
        "Repository": "https://github.com/baliuzeger/logrepl"
    },
    "split_keywords": [
        "repl",
        " log",
        " logging"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c60ffc09421939d9cb97581434e52ad9e7ec20a3ce77c8169c8b9d0d371c9d7d",
                "md5": "014614136eea3432a5a7485d941371c8",
                "sha256": "3b4737ea682e0303186ae07ab0053b5c416132950e80ab06a44e8f72801da022"
            },
            "downloads": -1,
            "filename": "logrepl-0.2.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "014614136eea3432a5a7485d941371c8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.6",
            "size": 9797,
            "upload_time": "2024-04-12T06:31:42",
            "upload_time_iso_8601": "2024-04-12T06:31:42.002248Z",
            "url": "https://files.pythonhosted.org/packages/c6/0f/fc09421939d9cb97581434e52ad9e7ec20a3ce77c8169c8b9d0d371c9d7d/logrepl-0.2.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d96b9d14e3c6c43826071edf5a593a6d7d1b47b8d2f1e09d28a78302db8c1fea",
                "md5": "368093a340e9992ab85b02ac053acda8",
                "sha256": "ebb34b158463e0d7efd50268bdcee8c638d719d0e9ef11f27e656c44ba6f6281"
            },
            "downloads": -1,
            "filename": "logrepl-0.2.5.tar.gz",
            "has_sig": false,
            "md5_digest": "368093a340e9992ab85b02ac053acda8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.6",
            "size": 8721,
            "upload_time": "2024-04-12T06:31:45",
            "upload_time_iso_8601": "2024-04-12T06:31:45.385381Z",
            "url": "https://files.pythonhosted.org/packages/d9/6b/9d14e3c6c43826071edf5a593a6d7d1b47b8d2f1e09d28a78302db8c1fea/logrepl-0.2.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-12 06:31:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "baliuzeger",
    "github_project": "logrepl",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "logrepl"
}
        
Elapsed time: 0.22487s