Created
August 27, 2013 17:54
-
-
Save jgraham/6356797 to your computer and use it in GitHub Desktop.
Structured logging logger.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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