Skip to content

Instantly share code, notes, and snippets.

@jgraham
Created August 27, 2013 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgraham/6356797 to your computer and use it in GitHub Desktop.
Save jgraham/6356797 to your computer and use it in GitHub Desktop.
Structured logging logger.
class StructuredLogger(object):
def __init__(self):
self._log = logger
def _test_log_func(level_name):
def log(self, params):
all_params = {"_thread":threading.current_thread().name,
"_process":multiprocessing.current_process().name}
all_params.update(params)
self._log.log_structured(level_name, all_params)
return log
for name in ["critical", "error", "warning", "info", "debug",
"test-start", "test-end", "test-pass", "test-fail",
"test-known-fail", "process-crash"]:
parts = name.split("-")
action = "-".join(item.upper() for item in parts)
for i, part in enumerate(parts[1:]):
parts[i+1] = part.title()
func_name = "".join(parts)
setattr(StructuredLogger, func_name, _test_log_func(action))
l = StructuredLogger()
l.debug({"test":"foo"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment