wrap-logger


Namewrap-logger JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/MiguelGuthridge/python-wrap-logger
SummaryA library to wrap around objects and modules in Python and log property accesses and calls
upload_time2023-08-17 14:26:15
maintainer
docs_urlNone
authorMiguel Guthridge
requires_python>=3.9,<4.0
licenseMIT
keywords log logger wrapper wrap
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Wrap Logger

A library to wrap around objects and modules in Python and log property
accesses and calls.

## Rationale

In some cases when programming, errors can break things to the point where
you have no idea where things went wrong, for example, crashing the runtime
environment before a backtrace can be printed. In these cases, it can be
extremely useful to log changes to data that are potentially related to the
issue, but doing so can be tedious and slow. I needed a simple solution to
easily inject logging into objects, and so I created `wrap-logger`.

## Usage

Using `wrap-logger` is simple. Simply call the `wrap` function, which will
return a wrapped version.

### With a module

```py
import foo
from wrap_logger import wrap

# Now all function calls and global reads/writes will be logged
foo = wrap(foo)
```

### With a class

```py
from wrap_logger import wrap

class Simple:
    """Simple class for testing purposes"""
    def __init__(self) -> None:
        self.value = 42

    def __repr__(self) -> str:
        return 'simple'

    def echo(self, value: str) -> str:
        return value


obj = wrap(Simple())


# Getting a property causes things to be logged
variable = obj.value
# [WRAP LOG] > Get  simple.value
# [WRAP LOG] < Get  simple.value: gave 42

# Same for setting properties
obj.value = 43
# [WRAP LOG] > Set  simple.value: 42 -> 43
# [WRAP LOG] < Set  simple.value

# And calling functions
obj.echo('hello world')
# [WRAP LOG] > Call simple.echo('hello world')
# [WRAP LOG] < Call simple.echo('hello world'): returned 'hello world'
```

### Without Pip

`wrap-logger` requires no dependencies, and can even function with some parts
of the standard library missing. Simply head over to the releases tab where the
`wrap-logger.zip` file is attached, then extract it into a new folder within
your project, where you can import it easily. You should then be able to use it
normally, importing it from your desired location.

## Implementation details

`wrap-logger` wraps objects in a `WrapLogger` class. Although the class does
override the `__class__` property so as to fool `isinstance` checks, fooling
the `type` function does not appear to work, so those checks may fail leading
to potentially erroneous behaviour.

## TODOs

`wrap-logger` was thrown together so I could quickly debug another project, so
it is incomplete. If there is demand (hint: create an issue), I will be happy
to try my hand at implementing the following features:

* [ ] Specify output file that `wrap-logger` prints to
* [ ] Recursive wrapping, so that attributes of attributes are also logged
* [ ] Configuration on what is/isn't logged (currently it just prints
      everything)
* [ ] Figure out what happens if you use `wrap-logger` on itself. Does it
      crash? Does it delete System 32? Does the space-time continuum collapse?
      Who knows!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/MiguelGuthridge/python-wrap-logger",
    "name": "wrap-logger",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "log,logger,wrapper,wrap",
    "author": "Miguel Guthridge",
    "author_email": "hdsq@outlook.com.au",
    "download_url": "https://files.pythonhosted.org/packages/c1/30/644ee67838d31075984f6b13ab89a3757d8b5d6db6949d4c058ab3dd94ff/wrap_logger-0.1.0.tar.gz",
    "platform": null,
    "description": "# Wrap Logger\n\nA library to wrap around objects and modules in Python and log property\naccesses and calls.\n\n## Rationale\n\nIn some cases when programming, errors can break things to the point where\nyou have no idea where things went wrong, for example, crashing the runtime\nenvironment before a backtrace can be printed. In these cases, it can be\nextremely useful to log changes to data that are potentially related to the\nissue, but doing so can be tedious and slow. I needed a simple solution to\neasily inject logging into objects, and so I created `wrap-logger`.\n\n## Usage\n\nUsing `wrap-logger` is simple. Simply call the `wrap` function, which will\nreturn a wrapped version.\n\n### With a module\n\n```py\nimport foo\nfrom wrap_logger import wrap\n\n# Now all function calls and global reads/writes will be logged\nfoo = wrap(foo)\n```\n\n### With a class\n\n```py\nfrom wrap_logger import wrap\n\nclass Simple:\n    \"\"\"Simple class for testing purposes\"\"\"\n    def __init__(self) -> None:\n        self.value = 42\n\n    def __repr__(self) -> str:\n        return 'simple'\n\n    def echo(self, value: str) -> str:\n        return value\n\n\nobj = wrap(Simple())\n\n\n# Getting a property causes things to be logged\nvariable = obj.value\n# [WRAP LOG] > Get  simple.value\n# [WRAP LOG] < Get  simple.value: gave 42\n\n# Same for setting properties\nobj.value = 43\n# [WRAP LOG] > Set  simple.value: 42 -> 43\n# [WRAP LOG] < Set  simple.value\n\n# And calling functions\nobj.echo('hello world')\n# [WRAP LOG] > Call simple.echo('hello world')\n# [WRAP LOG] < Call simple.echo('hello world'): returned 'hello world'\n```\n\n### Without Pip\n\n`wrap-logger` requires no dependencies, and can even function with some parts\nof the standard library missing. Simply head over to the releases tab where the\n`wrap-logger.zip` file is attached, then extract it into a new folder within\nyour project, where you can import it easily. You should then be able to use it\nnormally, importing it from your desired location.\n\n## Implementation details\n\n`wrap-logger` wraps objects in a `WrapLogger` class. Although the class does\noverride the `__class__` property so as to fool `isinstance` checks, fooling\nthe `type` function does not appear to work, so those checks may fail leading\nto potentially erroneous behaviour.\n\n## TODOs\n\n`wrap-logger` was thrown together so I could quickly debug another project, so\nit is incomplete. If there is demand (hint: create an issue), I will be happy\nto try my hand at implementing the following features:\n\n* [ ] Specify output file that `wrap-logger` prints to\n* [ ] Recursive wrapping, so that attributes of attributes are also logged\n* [ ] Configuration on what is/isn't logged (currently it just prints\n      everything)\n* [ ] Figure out what happens if you use `wrap-logger` on itself. Does it\n      crash? Does it delete System 32? Does the space-time continuum collapse?\n      Who knows!\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A library to wrap around objects and modules in Python and log property accesses and calls",
    "version": "0.1.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/MiguelGuthridge/python-wrap-logger/issues",
        "Documentation": "https://github.com/MiguelGuthridge/python-wrap-logger",
        "Homepage": "https://github.com/MiguelGuthridge/python-wrap-logger",
        "Online Documentation": "https://github.com/MiguelGuthridge/python-wrap-logger",
        "Repository": "https://github.com/MiguelGuthridge/python-wrap-logger"
    },
    "split_keywords": [
        "log",
        "logger",
        "wrapper",
        "wrap"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "449f70f9af4aafcf704ed57a9b747d7d88f11c9b490d6edc2eda186975d10769",
                "md5": "34c1df2eed254c677ad833903e3d577e",
                "sha256": "f7d373e94dd4c9dc8c2d5db3b9c82c89c886b3d6960cf15f9056805d1ed2dadf"
            },
            "downloads": -1,
            "filename": "wrap_logger-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "34c1df2eed254c677ad833903e3d577e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 5670,
            "upload_time": "2023-08-17T14:26:13",
            "upload_time_iso_8601": "2023-08-17T14:26:13.603853Z",
            "url": "https://files.pythonhosted.org/packages/44/9f/70f9af4aafcf704ed57a9b747d7d88f11c9b490d6edc2eda186975d10769/wrap_logger-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c130644ee67838d31075984f6b13ab89a3757d8b5d6db6949d4c058ab3dd94ff",
                "md5": "1024133002883763f8b660c8d18b7801",
                "sha256": "d34d32fc2efbc138fb887d379184c8dcbc626276771312c7becb4b8d93ac133e"
            },
            "downloads": -1,
            "filename": "wrap_logger-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1024133002883763f8b660c8d18b7801",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 4838,
            "upload_time": "2023-08-17T14:26:15",
            "upload_time_iso_8601": "2023-08-17T14:26:15.204433Z",
            "url": "https://files.pythonhosted.org/packages/c1/30/644ee67838d31075984f6b13ab89a3757d8b5d6db6949d4c058ab3dd94ff/wrap_logger-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-17 14:26:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MiguelGuthridge",
    "github_project": "python-wrap-logger",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "wrap-logger"
}
        
Elapsed time: 0.12277s