]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
tinfoil: support other fds, enable color support
authorChristopher Larson <chris_larson@mentor.com>
Sat, 26 Jan 2013 00:56:30 +0000 (17:56 -0700)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 31 Jan 2013 12:37:32 +0000 (12:37 +0000)
Rather than only handling sys.stdout, also support any arbitrary file object,
and enable color for the formatter if that file is a tty.

Signed-off-by: Christopher Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
lib/bb/tinfoil.py

index 73d8fe92a814fa35788ffeaf15a95525b1707f7f..cb53f3e54fd18753e2b99b3d339af9933949b26c 100644 (file)
@@ -29,15 +29,17 @@ from bb.cooker import state
 import bb.fetch2
 
 class Tinfoil:
-    def __init__(self):
+    def __init__(self, output=sys.stdout):
         # Needed to avoid deprecation warnings with python 2.6
         warnings.filterwarnings("ignore", category=DeprecationWarning)
 
         # Set up logging
         self.logger = logging.getLogger('BitBake')
-        console = logging.StreamHandler(sys.stdout)
-        format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
+        console = logging.StreamHandler(output)
         bb.msg.addDefaultlogFilter(console)
+        format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
+        if output.isatty():
+            format.enable_color()
         console.setFormatter(format)
         self.logger.addHandler(console)