glog for Python
===============
.. image:: https://travis-ci.org/benley/python-glog.svg?branch=master
:target: https://travis-ci.org/benley/python-glog
A simple Google-style logging wrapper for Python.
This library attempts to greatly simplify logging in Python applications.
Nobody wants to spend hours pouring over the PEP 282 logger documentation, and
almost nobody actually needs things like loggers that can be reconfigured over
the network. We just want to get on with writing our apps.
Styled somewhat after the twitter.common.log_ interface, which in turn was
modeled after Google's internal python logger, which was `never actually
released`_ to the wild, and which in turn was based on the `C++ glog library`_.
Core benefits
-------------
- You and your code don't need to care about how logging works. Unless you
want to, of course.
- No more complicated setup boilerplate!
- Your apps and scripts will all have a consistent log format, and the same
predictable behaviours.
This library configures the root logger, so nearly everything you import that
uses the standard Python logging module will play along nicely.
Behaviours
----------
- Messages are always written to stderr.
- Lines are prefixed with a google-style log prefix, of the form
``E0924 22:19:15.123456 19552 filename.py:87] Log message blah blah``
Splitting on spaces, the fields are:
1. The first character is the log level, followed by MMDD (month, day)
2. HH:MM:SS.microseconds
3. Process ID
4. basename\_of\_sourcefile.py:linenumber]
5. The body of the log message.
Example use
-----------
.. code:: python
import glog as log
log.setLevel("INFO") # Integer levels are also allowed.
log.info("It works.")
log.warn("Something not ideal")
log.error("Something went wrong")
log.fatal("AAAAAAAAAAAAAAA!")
If your app uses gflags_, it will automatically gain a ``--verbosity`` flag,
and you can skip calling ``log.setLevel``. Just import glog and start logging.
Check macros / assert helpers
-----------------------------
`Like the C++ version of glog`_, python-glog provides a set of check macros
[1]_ that help document and enforce invariants. These provide a detailed
message indicating what values caused the assertion to fail, along with a stack
trace identifying the code-path that caused the failure, hopefully making it
easier to reproduce the error. Failed checks raise the FailedCheckException.
You may find these more convenient and/or more familiar than standard Python
asserts, particularly if you are working in a mixed C++ and Python codebase.
.. code:: python
import glog as log
import math
def compute_something(a):
log.check_eq(type(a), float) # require floating point types
log.check_ge(a, 0) # require non-negative values
value = math.sqrt(a)
return value
if __name__ == '__main__':
compute_something(10)
Provided check functions:
.. code:: python
check(condition)
check_eq(obj1, obj2)
check_ne(obj1, obj2)
check_le(obj1, obj2)
check_ge(obj1, obj2)
check_lt(obj1, obj2)
check_gt(obj1, obj2)
check_notnone(obj1, obj2)
Happy logging!
.. _twitter.common.log: https://github.com/twitter/commons/tree/master/src/python/twitter/common/log
.. _never actually released: https://groups.google.com/d/msg/google-glog/a_JcyJ4p8MQ/Xu-vDPiuCCYJ
.. _C++ glog library: https://github.com/google/glog
.. _gflags: https://github.com/google/python-gflags
.. _Like the C++ version of glog: https://htmlpreview.github.io/?https://github.com/google/glog/master/doc/glog.html#check
.. [1] Technically these are functions, not macros. Python does not have
syntactic macros in the sense that C++ and most lisp-like languages do.
Raw data
{
"_id": null,
"home_page": "https://github.com/benley/python-glog",
"name": "glog",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Benjamin Staffin",
"author_email": "benley@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d7/7f/082e2a23f8dff00bd98a7ff7db1b27a3cc66012f2db952a5fc00d8f66b13/glog-0.3.1.tar.gz",
"platform": "any",
"description": "glog for Python\n===============\n\n.. image:: https://travis-ci.org/benley/python-glog.svg?branch=master\n :target: https://travis-ci.org/benley/python-glog\n\nA simple Google-style logging wrapper for Python.\n\nThis library attempts to greatly simplify logging in Python applications.\nNobody wants to spend hours pouring over the PEP 282 logger documentation, and\nalmost nobody actually needs things like loggers that can be reconfigured over\nthe network. We just want to get on with writing our apps.\n\nStyled somewhat after the twitter.common.log_ interface, which in turn was\nmodeled after Google's internal python logger, which was `never actually\nreleased`_ to the wild, and which in turn was based on the `C++ glog library`_.\n\nCore benefits\n-------------\n\n- You and your code don't need to care about how logging works. Unless you\n want to, of course.\n\n- No more complicated setup boilerplate!\n\n- Your apps and scripts will all have a consistent log format, and the same\n predictable behaviours.\n\nThis library configures the root logger, so nearly everything you import that\nuses the standard Python logging module will play along nicely.\n\nBehaviours\n----------\n\n- Messages are always written to stderr.\n\n- Lines are prefixed with a google-style log prefix, of the form\n\n``E0924 22:19:15.123456 19552 filename.py:87] Log message blah blah``\n\nSplitting on spaces, the fields are:\n\n1. The first character is the log level, followed by MMDD (month, day)\n2. HH:MM:SS.microseconds\n3. Process ID\n4. basename\\_of\\_sourcefile.py:linenumber]\n5. The body of the log message.\n\nExample use\n-----------\n\n.. code:: python\n\n import glog as log\n\n log.setLevel(\"INFO\") # Integer levels are also allowed.\n log.info(\"It works.\")\n log.warn(\"Something not ideal\")\n log.error(\"Something went wrong\")\n log.fatal(\"AAAAAAAAAAAAAAA!\")\n\nIf your app uses gflags_, it will automatically gain a ``--verbosity`` flag,\nand you can skip calling ``log.setLevel``. Just import glog and start logging.\n\nCheck macros / assert helpers\n-----------------------------\n\n`Like the C++ version of glog`_, python-glog provides a set of check macros\n[1]_ that help document and enforce invariants. These provide a detailed\nmessage indicating what values caused the assertion to fail, along with a stack\ntrace identifying the code-path that caused the failure, hopefully making it\neasier to reproduce the error. Failed checks raise the FailedCheckException.\nYou may find these more convenient and/or more familiar than standard Python\nasserts, particularly if you are working in a mixed C++ and Python codebase.\n\n\n.. code:: python\n\n import glog as log\n import math\n\n def compute_something(a):\n log.check_eq(type(a), float) # require floating point types\n log.check_ge(a, 0) # require non-negative values\n value = math.sqrt(a)\n return value\n\n if __name__ == '__main__':\n compute_something(10)\n\n\nProvided check functions:\n\n.. code:: python\n\n check(condition)\n check_eq(obj1, obj2)\n check_ne(obj1, obj2)\n check_le(obj1, obj2)\n check_ge(obj1, obj2)\n check_lt(obj1, obj2)\n check_gt(obj1, obj2)\n check_notnone(obj1, obj2)\n\n\nHappy logging!\n\n.. _twitter.common.log: https://github.com/twitter/commons/tree/master/src/python/twitter/common/log\n\n.. _never actually released: https://groups.google.com/d/msg/google-glog/a_JcyJ4p8MQ/Xu-vDPiuCCYJ\n\n.. _C++ glog library: https://github.com/google/glog\n\n.. _gflags: https://github.com/google/python-gflags\n\n.. _Like the C++ version of glog: https://htmlpreview.github.io/?https://github.com/google/glog/master/doc/glog.html#check\n\n.. [1] Technically these are functions, not macros. Python does not have\n syntactic macros in the sense that C++ and most lisp-like languages do.\n\n\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "Simple Google-style logging wrapper for Python.",
"version": "0.3.1",
"project_urls": {
"Homepage": "https://github.com/benley/python-glog"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3942d2502683e9d9086cba5fb741c9b66c72ab1a852d046e1d54d2b80221b69f",
"md5": "717a5e3250ef4f6b39236f90bdf884f2",
"sha256": "88cee83dea8bddf73db7edbf5bd697237628389ef476c0a0ecad639c606189e5"
},
"downloads": -1,
"filename": "glog-0.3.1-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "717a5e3250ef4f6b39236f90bdf884f2",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 7767,
"upload_time": "2016-12-14T01:52:16",
"upload_time_iso_8601": "2016-12-14T01:52:16.671882Z",
"url": "https://files.pythonhosted.org/packages/39/42/d2502683e9d9086cba5fb741c9b66c72ab1a852d046e1d54d2b80221b69f/glog-0.3.1-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d77f082e2a23f8dff00bd98a7ff7db1b27a3cc66012f2db952a5fc00d8f66b13",
"md5": "00367eb69e7e20f4929725ca35f1a8a1",
"sha256": "b721edef6009eabc0b4d9f2619e153d2627a7b71a3657c8ed69f02ef7c78be97"
},
"downloads": -1,
"filename": "glog-0.3.1.tar.gz",
"has_sig": false,
"md5_digest": "00367eb69e7e20f4929725ca35f1a8a1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5305,
"upload_time": "2016-12-14T01:52:18",
"upload_time_iso_8601": "2016-12-14T01:52:18.216465Z",
"url": "https://files.pythonhosted.org/packages/d7/7f/082e2a23f8dff00bd98a7ff7db1b27a3cc66012f2db952a5fc00d8f66b13/glog-0.3.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2016-12-14 01:52:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "benley",
"github_project": "python-glog",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"lcname": "glog"
}