Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4395)

Unified Diff: chrome/test/kasko/py/kasko/json_logging_handler.py

Issue 1834773002: Add a JSON logging handler to the Kasko integration tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/kasko/py/kasko/config.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/kasko/py/kasko/json_logging_handler.py
diff --git a/chrome/test/kasko/py/kasko/json_logging_handler.py b/chrome/test/kasko/py/kasko/json_logging_handler.py
new file mode 100755
index 0000000000000000000000000000000000000000..8a26c38bc96f5501ebdf24b18788c57fc48a3d81
--- /dev/null
+++ b/chrome/test/kasko/py/kasko/json_logging_handler.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Logging handler used to log into a JSON file."""
+
+import json
+import logging
+
+
+class JSONLoggingHandler(logging.Handler):
+ """A logging handler that forwards log messages into a JSON file."""
+
+ def __init__(self, json_file):
+ logging.Handler.__init__(self)
+ formatter = logging.Formatter('%(name)s:%(message)s')
+ self.setFormatter(formatter)
+ self.json_file_ = json_file
+ self.log_messages_ = []
+
+ def close(self):
+ """Dump the list of log messages into the JSON file."""
+ with open(self.json_file_, 'w') as f:
+ f.write(json.dumps(self.log_messages_))
+ logging.Handler.close(self)
+
+ def emit(self, record):
+ """Append the record to list of messages."""
+ self.log_messages_.append({record.levelname: self.format(record)})
« no previous file with comments | « chrome/test/kasko/py/kasko/config.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698