Skip to main content
https://travis-ci.org/benley/python-glog.svg?branch=master

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

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!

Metadata

Release files for glog2 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for glog2 0.0.4
File Size Uploaded
glog2-0.0.4.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for glog2 0.0.4
File Interpreter ABI Platform
glog2-0.0.4-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 12.2 kB

Release files / glog2-0.0.4.tar.gz

Download URL glog2-0.0.4.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
74d56e8cf313cf19b17d202ec1c595980389648e34cf3818ef72af5e713c25c2
BLAKE2b-256 checksum
How to use checksums
f0bb1e6a9b33b0400902e4b044a0aa82c9124c99244f1afd019cba7cee9dd99c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.5

Release files / glog2-0.0.4-py2.py3-none-any.whl

Download URL glog2-0.0.4-py2.py3-none-any.whl
Size 6.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
c317e6fd934e0bdcf1b437f388dd1eca0f7dd5f100bd6c75a359aad2b6df98b6
BLAKE2b-256 checksum
How to use checksums
ff96780a2c8c483893b7f5906e60ae3e4b02b1be1587c0968617c8dfb27645ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.5

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page