logtool


Namelogtool JSON
Version 0.4.post2 PyPI version JSON
download
home_pagehttps://github.com/clearclaw/logtool
SummaryMethods and tools that assist logging
upload_time2024-07-22 03:03:17
maintainerNone
docs_urlNone
authorJ C Lawrence
requires_python<4.0,>=3.7
licenseGPL-3.0-only
keywords logging exceptions callpoints call tracing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            logtool
=======

Methods and tools that assist logging.  Can be installed from PyPI:

::

  $ pip install logtool

log\_call
---------

A decorator for function and method definitions that logs at DEBUG
level a variety of data about every call made to that entrypoint.

Intended to supercede @log_func and log_func_noargs (see below).  See
log\_func for example output.

Optional arguments:

log\_enter
  Log entrance to the decorated method.  Defaults to True.
log\_args
  Log the arguments passed to the decorated method.  Defaults to True.
log\_exit
  Log exit/returns from the decorated method along with the execution time. Defaults to True.
log\_rc
  Log the value returned by the decorated method.  Defaults to True.
log\_trace
  Log each line of the decorated method as it is executed.  Defaults to False.
log\_level
  Log level to use for the logging of the call.  Defaults to logging.DBEUG.

::

  @logtool.log_call
  def a_method (...):
   ...etc...

::

  @logtool.log_call (log_args = False, log_rc = False)
  def big_complex_data (...):
   ...etc...

log\_func
---------

A decorator for function and method definitions that logs at DEBUG level
every call to that function or method along with its arguments.

eg

::

    @logtool.log_wrap
    def my_method (self, *args):
      ...stuff here...

Resulting log entry from a real production usage (with a few of the
argumentvalues redacted):

::

    Entered: function:test_tool.toolwrapper:email_report ((<test_tool.meshtool.Wrapper object at 0x7f19d4879c10>, path(u'../file.ext'), 'address@domain.com', 'address@domain.com', 'Interesting subject header') {})

The {} at the end shows that there were no named arguments passed to
that call, else they would be shown there.

log\_func\_noargs
-----------------

A decorator for function and method definitions that logs at DEBUG level
every call to that function or method but without any arguments. This
can be useful when traversing and dumping the arguments would be
execssively expensive, or would potentially create infinite loops.

eg

::

    @logtool.log_wrap_noargs
    def my_method (self, *args):
      ...stuff here...

log\_fault
----------

Logs an exception in a standardised form, including the source file and
line number of the exception, and if logging at DEBUG level, also logs a
stack trace along with all the variables in each stack frame. eg

In WARN or higher mode:

::

    CRITICAL <log_fault_impl:log_fault(24)> FAULT: /usr/local/lib/python2.7/dist-packages/workerd-0.1.26_gbb342e2-py2.7.egg/workerd/do.py(243): IOError(28, 'No space left on device')

When logging at DEBUG:

::

    CRITICAL <log_fault_impl:log_fault(24)> FAULT: /usr/local/lib/python2.7/dist-packages/workerd-0.1.26_gbb342e2-py2.7.egg/workerd/do.py(243): IOError(28, 'No space left on device')
    DEBUG <log_fault_impl:log_fault(26)> Locals by frame, innermost last:
    DEBUG <log_fault_impl:log_fault(30)> Frame run in /usr/local/lib/python2.7/dist-packages/workerd-0.1.26_gbb342e2-py2.7.egg/workerd/do.py at line 248
    DEBUG <log_fault_impl:log_fault(40)>                 self = <workerd.do.Do object at 0x7f5709e3d490>
    DEBUG <log_fault_impl:log_fault(40)>                    e = [Errno 28] No space left on device
    DEBUG <log_fault_impl:log_fault(40)>                   rc = 0
    DEBUG <log_fault_impl:log_fault(30)> Frame wrapper_args in build/bdist.linux-x86_64/egg/mppy/log_wrap.py at line 27
    DEBUG <log_fault_impl:log_fault(40)>                 args = (<workerd.do.Do object at 0x7f5709e3d490>,)
    DEBUG <log_fault_impl:log_fault(40)>                   fn = <function do_job at 0x7f570a2936e0>
    DEBUG <log_fault_impl:log_fault(40)>               kwargs = {}
    DEBUG <log_fault_impl:log_fault(30)> Frame do_job in /usr/local/lib/python2.7/dist-packages/workerd-0.1.26_gbb342e2-py2.7.egg/workerd/do.py at line 227
    DEBUG <log_fault_impl:log_fault(40)>                  toc = 1410867312.58
    DEBUG <log_fault_impl:log_fault(40)>                 self = <workerd.do.Do object at 0x7f5709e3d490>
    DEBUG <log_fault_impl:log_fault(40)>                  tic = 1410842559.54
    DEBUG <log_fault_impl:log_fault(40)>                   rc = -99
    DEBUG <log_fault_impl:log_fault(30)> Frame __setitem__ in build/bdist.linux-x86_64/egg/mppy/jsondict.py at line 69
    DEBUG <log_fault_impl:log_fault(40)>                 self = {u'status': u'pending', u'notified_for': u'pending
    DEBUG <log_fault_impl:log_fault(40)>                  key = execution_time
    DEBUG <log_fault_impl:log_fault(40)>                  val = 24753.043578
    DEBUG <log_fault_impl:log_fault(40)>               kwargs = {}
    DEBUG <log_fault_impl:log_fault(30)> Frame wrapper in build/bdist.linux-x86_64/egg/mppy/jsondict.py at line 80
    DEBUG <log_fault_impl:log_fault(40)>                 self = {u'status': u'pending', u'notified_for': u'pending
    DEBUG <log_fault_impl:log_fault(40)>               kwargs = {}
    DEBUG <log_fault_impl:log_fault(40)>                 attr = <bound method JsonDict.save of {u'status': u'pendi
    DEBUG <log_fault_impl:log_fault(40)>                 args = ()
    DEBUG <log_fault_impl:log_fault(40)>           was_loaded = True
    DEBUG <log_fault_impl:log_fault(30)> Frame save in build/bdist.linux-x86_64/egg/mppy/jsondict.py at line 46
    DEBUG <log_fault_impl:log_fault(40)>                force = False
    DEBUG <log_fault_impl:log_fault(40)>                 self = {u'status': u'pending', u'notified_for': u'pending
    DEBUG <log_fault_impl:log_fault(40)>                   fd = 5
    DEBUG <log_fault_impl:log_fault(40)>                   fn = /var/spool/matterport/workerd/generate_mesh/d34fea

time\_str
---------

Simply returns a time\_t (seconds since the epoch, possibly fractional)
in a simple consistent string form suitable for logfiles, reports and
the like.

See below under ``now`` for an example.

now
---

Reurns a tuple of the current time as a time\_t, and its matching
time\_str. Getting the two together allows the string to be used for
logs and the like, and the time_t to be used as a numeric.  eg:

::

    $ ipython
    Python 2.7.6 (default, Mar 22 2014, 22:59:56)
    Type "copyright", "credits" or "license" for more information.

    IPython 1.2.1 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.

    In [1]: import logtool

    In [2]: logtool.now ()
    Out[2]: (1411075417, '21:23:37 Thu 18 Sep 2014 Z+0000')

    In [3]: logtool.time_str (logtool.now ()[0])
    Out[3]: '14:23:42 Thu 18 Sep 2014 Z+0000'

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/clearclaw/logtool",
    "name": "logtool",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.7",
    "maintainer_email": null,
    "keywords": "logging, exceptions, callpoints, call tracing",
    "author": "J C Lawrence",
    "author_email": "claw@kanga.nu",
    "download_url": "https://files.pythonhosted.org/packages/d8/da/5974a7a31b0e8d7fa2510e53c795740d2af5438f15186e3bf1506a31e647/logtool-0.4.post2.tar.gz",
    "platform": null,
    "description": "logtool\n=======\n\nMethods and tools that assist logging.  Can be installed from PyPI:\n\n::\n\n  $ pip install logtool\n\nlog\\_call\n---------\n\nA decorator for function and method definitions that logs at DEBUG\nlevel a variety of data about every call made to that entrypoint.\n\nIntended to supercede @log_func and log_func_noargs (see below).  See\nlog\\_func for example output.\n\nOptional arguments:\n\nlog\\_enter\n  Log entrance to the decorated method.  Defaults to True.\nlog\\_args\n  Log the arguments passed to the decorated method.  Defaults to True.\nlog\\_exit\n  Log exit/returns from the decorated method along with the execution time. Defaults to True.\nlog\\_rc\n  Log the value returned by the decorated method.  Defaults to True.\nlog\\_trace\n  Log each line of the decorated method as it is executed.  Defaults to False.\nlog\\_level\n  Log level to use for the logging of the call.  Defaults to logging.DBEUG.\n\n::\n\n  @logtool.log_call\n  def a_method (...):\n   ...etc...\n\n::\n\n  @logtool.log_call (log_args = False, log_rc = False)\n  def big_complex_data (...):\n   ...etc...\n\nlog\\_func\n---------\n\nA decorator for function and method definitions that logs at DEBUG level\nevery call to that function or method along with its arguments.\n\neg\n\n::\n\n    @logtool.log_wrap\n    def my_method (self, *args):\n      ...stuff here...\n\nResulting log entry from a real production usage (with a few of the\nargumentvalues redacted):\n\n::\n\n    Entered: function:test_tool.toolwrapper:email_report ((<test_tool.meshtool.Wrapper object at 0x7f19d4879c10>, path(u'../file.ext'), 'address@domain.com', 'address@domain.com', 'Interesting subject header') {})\n\nThe {} at the end shows that there were no named arguments passed to\nthat call, else they would be shown there.\n\nlog\\_func\\_noargs\n-----------------\n\nA decorator for function and method definitions that logs at DEBUG level\nevery call to that function or method but without any arguments. This\ncan be useful when traversing and dumping the arguments would be\nexecssively expensive, or would potentially create infinite loops.\n\neg\n\n::\n\n    @logtool.log_wrap_noargs\n    def my_method (self, *args):\n      ...stuff here...\n\nlog\\_fault\n----------\n\nLogs an exception in a standardised form, including the source file and\nline number of the exception, and if logging at DEBUG level, also logs a\nstack trace along with all the variables in each stack frame. eg\n\nIn WARN or higher mode:\n\n::\n\n    CRITICAL <log_fault_impl:log_fault(24)> FAULT: /usr/local/lib/python2.7/dist-packages/workerd-0.1.26_gbb342e2-py2.7.egg/workerd/do.py(243): IOError(28, 'No space left on device')\n\nWhen logging at DEBUG:\n\n::\n\n    CRITICAL <log_fault_impl:log_fault(24)> FAULT: /usr/local/lib/python2.7/dist-packages/workerd-0.1.26_gbb342e2-py2.7.egg/workerd/do.py(243): IOError(28, 'No space left on device')\n    DEBUG <log_fault_impl:log_fault(26)> Locals by frame, innermost last:\n    DEBUG <log_fault_impl:log_fault(30)> Frame run in /usr/local/lib/python2.7/dist-packages/workerd-0.1.26_gbb342e2-py2.7.egg/workerd/do.py at line 248\n    DEBUG <log_fault_impl:log_fault(40)>                 self = <workerd.do.Do object at 0x7f5709e3d490>\n    DEBUG <log_fault_impl:log_fault(40)>                    e = [Errno 28] No space left on device\n    DEBUG <log_fault_impl:log_fault(40)>                   rc = 0\n    DEBUG <log_fault_impl:log_fault(30)> Frame wrapper_args in build/bdist.linux-x86_64/egg/mppy/log_wrap.py at line 27\n    DEBUG <log_fault_impl:log_fault(40)>                 args = (<workerd.do.Do object at 0x7f5709e3d490>,)\n    DEBUG <log_fault_impl:log_fault(40)>                   fn = <function do_job at 0x7f570a2936e0>\n    DEBUG <log_fault_impl:log_fault(40)>               kwargs = {}\n    DEBUG <log_fault_impl:log_fault(30)> Frame do_job in /usr/local/lib/python2.7/dist-packages/workerd-0.1.26_gbb342e2-py2.7.egg/workerd/do.py at line 227\n    DEBUG <log_fault_impl:log_fault(40)>                  toc = 1410867312.58\n    DEBUG <log_fault_impl:log_fault(40)>                 self = <workerd.do.Do object at 0x7f5709e3d490>\n    DEBUG <log_fault_impl:log_fault(40)>                  tic = 1410842559.54\n    DEBUG <log_fault_impl:log_fault(40)>                   rc = -99\n    DEBUG <log_fault_impl:log_fault(30)> Frame __setitem__ in build/bdist.linux-x86_64/egg/mppy/jsondict.py at line 69\n    DEBUG <log_fault_impl:log_fault(40)>                 self = {u'status': u'pending', u'notified_for': u'pending\n    DEBUG <log_fault_impl:log_fault(40)>                  key = execution_time\n    DEBUG <log_fault_impl:log_fault(40)>                  val = 24753.043578\n    DEBUG <log_fault_impl:log_fault(40)>               kwargs = {}\n    DEBUG <log_fault_impl:log_fault(30)> Frame wrapper in build/bdist.linux-x86_64/egg/mppy/jsondict.py at line 80\n    DEBUG <log_fault_impl:log_fault(40)>                 self = {u'status': u'pending', u'notified_for': u'pending\n    DEBUG <log_fault_impl:log_fault(40)>               kwargs = {}\n    DEBUG <log_fault_impl:log_fault(40)>                 attr = <bound method JsonDict.save of {u'status': u'pendi\n    DEBUG <log_fault_impl:log_fault(40)>                 args = ()\n    DEBUG <log_fault_impl:log_fault(40)>           was_loaded = True\n    DEBUG <log_fault_impl:log_fault(30)> Frame save in build/bdist.linux-x86_64/egg/mppy/jsondict.py at line 46\n    DEBUG <log_fault_impl:log_fault(40)>                force = False\n    DEBUG <log_fault_impl:log_fault(40)>                 self = {u'status': u'pending', u'notified_for': u'pending\n    DEBUG <log_fault_impl:log_fault(40)>                   fd = 5\n    DEBUG <log_fault_impl:log_fault(40)>                   fn = /var/spool/matterport/workerd/generate_mesh/d34fea\n\ntime\\_str\n---------\n\nSimply returns a time\\_t (seconds since the epoch, possibly fractional)\nin a simple consistent string form suitable for logfiles, reports and\nthe like.\n\nSee below under ``now`` for an example.\n\nnow\n---\n\nReurns a tuple of the current time as a time\\_t, and its matching\ntime\\_str. Getting the two together allows the string to be used for\nlogs and the like, and the time_t to be used as a numeric.  eg:\n\n::\n\n    $ ipython\n    Python 2.7.6 (default, Mar 22 2014, 22:59:56)\n    Type \"copyright\", \"credits\" or \"license\" for more information.\n\n    IPython 1.2.1 -- An enhanced Interactive Python.\n    ?         -> Introduction and overview of IPython's features.\n    %quickref -> Quick reference.\n    help      -> Python's own help system.\n    object?   -> Details about 'object', use 'object??' for extra details.\n\n    In [1]: import logtool\n\n    In [2]: logtool.now ()\n    Out[2]: (1411075417, '21:23:37 Thu 18 Sep 2014 Z+0000')\n\n    In [3]: logtool.time_str (logtool.now ()[0])\n    Out[3]: '14:23:42 Thu 18 Sep 2014 Z+0000'\n",
    "bugtrack_url": null,
    "license": "GPL-3.0-only",
    "summary": "Methods and tools that assist logging",
    "version": "0.4.post2",
    "project_urls": {
        "Homepage": "https://github.com/clearclaw/logtool",
        "Repository": "https://github.com/clearclaw/logtool"
    },
    "split_keywords": [
        "logging",
        " exceptions",
        " callpoints",
        " call tracing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a7107214c164586762ad9a4bdddb34e3b19ac0f233acd27862596ae1a8113374",
                "md5": "163ac2fa4f0c93886ea827f0fc9b9dcf",
                "sha256": "5f562a83e3d1323bd93f5ff55ac82b1bc00084f898067c4adf30e93394f7ef32"
            },
            "downloads": -1,
            "filename": "logtool-0.4.post2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "163ac2fa4f0c93886ea827f0fc9b9dcf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.7",
            "size": 9316,
            "upload_time": "2024-07-22T03:03:15",
            "upload_time_iso_8601": "2024-07-22T03:03:15.581114Z",
            "url": "https://files.pythonhosted.org/packages/a7/10/7214c164586762ad9a4bdddb34e3b19ac0f233acd27862596ae1a8113374/logtool-0.4.post2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d8da5974a7a31b0e8d7fa2510e53c795740d2af5438f15186e3bf1506a31e647",
                "md5": "0cb321d9afa436debf5487e6ca3ff405",
                "sha256": "78d4669f5be91591de7278947da6d8a4f15ab5016ee55aa39f9b000ef113a839"
            },
            "downloads": -1,
            "filename": "logtool-0.4.post2.tar.gz",
            "has_sig": false,
            "md5_digest": "0cb321d9afa436debf5487e6ca3ff405",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.7",
            "size": 8244,
            "upload_time": "2024-07-22T03:03:17",
            "upload_time_iso_8601": "2024-07-22T03:03:17.169593Z",
            "url": "https://files.pythonhosted.org/packages/d8/da/5974a7a31b0e8d7fa2510e53c795740d2af5438f15186e3bf1506a31e647/logtool-0.4.post2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-22 03:03:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "clearclaw",
    "github_project": "logtool",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "logtool"
}
        
Elapsed time: 0.34813s