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

Unified Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/system/log_utils.py

Issue 2948043002: webkitpy: Add time output to the start of logging messages. (Closed)
Patch Set: git cl try Created 3 years, 6 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 | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/common/system/log_utils_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Tools/Scripts/webkitpy/common/system/log_utils.py
diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/common/system/log_utils.py b/third_party/WebKit/Tools/Scripts/webkitpy/common/system/log_utils.py
index a862bd5783ff7916fb61226101861a3386e29b50..75471196080056d7e40220791a5a40c21f89ecd4 100644
--- a/third_party/WebKit/Tools/Scripts/webkitpy/common/system/log_utils.py
+++ b/third_party/WebKit/Tools/Scripts/webkitpy/common/system/log_utils.py
@@ -28,11 +28,12 @@ import sys
_log = logging.getLogger(__name__)
-def _default_handlers(stream, logging_level):
+def _default_handlers(stream, logging_level, include_time):
"""Return a list of the default logging handlers to use.
Args:
stream: See the configure_logging() docstring.
+ include_time: See the configure_logging() docstring.
"""
# Create the filter.
def should_log(record):
@@ -46,10 +47,15 @@ def _default_handlers(stream, logging_level):
# Create the handler.
handler = logging.StreamHandler(stream)
+ if include_time:
+ prefix = '%(asctime)s - '
+ else:
+ prefix = ''
+
if logging_level == logging.DEBUG:
- formatter = logging.Formatter('%(name)s: [%(levelname)s] %(message)s')
+ formatter = logging.Formatter(prefix + '%(name)s: [%(levelname)s] %(message)s')
else:
- formatter = logging.Formatter('%(message)s')
+ formatter = logging.Formatter(prefix + '%(message)s')
handler.setFormatter(formatter)
handler.addFilter(logging_filter)
@@ -58,7 +64,7 @@ def _default_handlers(stream, logging_level):
def configure_logging(logging_level=None, logger=None, stream=None,
- handlers=None):
+ handlers=None, include_time=True):
"""Configure logging for standard purposes.
Returns:
@@ -80,6 +86,9 @@ def configure_logging(logging_level=None, logger=None, stream=None,
handlers: A list of logging.Handler instances to add to the logger
being configured. If this parameter is provided, then the
stream parameter is not used.
+ include_time: Include time information at the start of every log message.
+ Useful for understanding how much time has passed between
+ subsequent log messages.
"""
# If the stream does not define an "encoding" data attribute, the
# logging module can throw an error like the following:
@@ -96,7 +105,7 @@ def configure_logging(logging_level=None, logger=None, stream=None,
if stream is None:
stream = sys.stderr
if handlers is None:
- handlers = _default_handlers(stream, logging_level)
+ handlers = _default_handlers(stream, logging_level, include_time)
logger.setLevel(logging_level)
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/common/system/log_utils_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698