Simple Google-style logging wrapper for Python.
Project description
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:
The first character is the log level, followed by MMDD (month, day)
HH:MM:SS.microseconds
Process ID
basename_of_sourcefile.py:linenumber]
The body of the log message.
Example use
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.
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:
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!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file glog-0.3.1.tar.gz
.
File metadata
- Download URL: glog-0.3.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b721edef6009eabc0b4d9f2619e153d2627a7b71a3657c8ed69f02ef7c78be97 |
|
MD5 | 00367eb69e7e20f4929725ca35f1a8a1 |
|
BLAKE2b-256 | d77f082e2a23f8dff00bd98a7ff7db1b27a3cc66012f2db952a5fc00d8f66b13 |
File details
Details for the file glog-0.3.1-py2.py3-none-any.whl
.
File metadata
- Download URL: glog-0.3.1-py2.py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88cee83dea8bddf73db7edbf5bd697237628389ef476c0a0ecad639c606189e5 |
|
MD5 | 717a5e3250ef4f6b39236f90bdf884f2 |
|
BLAKE2b-256 | 3942d2502683e9d9086cba5fb741c9b66c72ab1a852d046e1d54d2b80221b69f |