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

Unified Diff: build/android/pylib/utils/logging_utils.py

Issue 1418833005: [gms updater] Fixes and tests to prepare activation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use SDK/library appropriately Created 5 years, 1 month 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 | « build/android/play_services/utils.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/utils/logging_utils.py
diff --git a/build/android/pylib/utils/logging_utils.py b/build/android/pylib/utils/logging_utils.py
index 78a5276b68676a6075e24bf581abd5baf5297645..326a8b0a20e32d90db509aa137b7eeba3e534135 100644
--- a/build/android/pylib/utils/logging_utils.py
+++ b/build/android/pylib/utils/logging_utils.py
@@ -36,6 +36,10 @@ class ColorStreamHandler(logging.StreamHandler):
logging.CRITICAL: colorama.Back.RED + colorama.Style.BRIGHT,
}
+ def __init__(self, force_color=False):
+ super(ColorStreamHandler, self).__init__()
+ self.force_color = force_color
+
@property
def is_tty(self):
isatty = getattr(self.stream, 'isatty', None)
@@ -44,8 +48,9 @@ class ColorStreamHandler(logging.StreamHandler):
#override
def format(self, record):
message = logging.StreamHandler.format(self, record)
- if self.is_tty:
+ if self.force_color or self.is_tty:
return self.Colorize(message, record.levelno)
+ return message
def Colorize(self, message, log_level):
try:
@@ -54,16 +59,19 @@ class ColorStreamHandler(logging.StreamHandler):
return message
@staticmethod
- def MakeDefault():
+ def MakeDefault(force_color=False):
"""
Replaces the default logging handlers with a coloring handler. To use
a colorizing handler at the same time as others, either register them
after this call, or add the ColorStreamHandler on the logger using
Logger.addHandler()
+
+ Args:
+ force_color: Set to True to bypass the tty check and always colorize.
"""
# If the existing handlers aren't removed, messages are duplicated
logging.getLogger().handlers = []
- logging.getLogger().addHandler(ColorStreamHandler())
+ logging.getLogger().addHandler(ColorStreamHandler(force_color))
@contextlib.contextmanager
« no previous file with comments | « build/android/play_services/utils.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698