From 76e1bf4dcb68341249417f291c74f72dc84c18e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Tue, 27 Jan 2009 20:54:22 +0100 Subject: Fix logging in bpython --- portato/log.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'portato/log.py') diff --git a/portato/log.py b/portato/log.py index 9c5ebd2..97b1493 100644 --- a/portato/log.py +++ b/portato/log.py @@ -39,11 +39,16 @@ class OutputFormatter (logging.Formatter): for key, value in self.colors.iteritems(): self.colors[key] = "\x1b[01;%02dm*\x1b[39;49;00m" % value + if hasattr(sys.stderr, "fileno"): + self.istty = os.isatty(sys.stderr.fileno()) + else: + self.istty = False # no fileno -> save default + def format (self, record): string = logging.Formatter.format(self, record) color = None - if os.isatty(sys.stderr.fileno()): + if self.istty: if record.levelno <= logging.DEBUG: color = self.colors["blue"] elif record.levelno <= logging.INFO: -- cgit v1.2.3