From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: Seth Bollinger <seth.boll@gmail.com>
Cc: "bitbake-devel@lists.openembedded.org"
<bitbake-devel@lists.openembedded.org>
Subject: Re: [PATCH v2] bitbake: Colorize knotty interactive console output
Date: Wed, 14 Nov 2012 23:26:17 +0000 [thread overview]
Message-ID: <1352935577.3709.7.camel@ted> (raw)
In-Reply-To: <CA+JN8xMP_dhBBiFGJx2qjNs1mpWox98=BaKixPOtX_BBb3rO-g@mail.gmail.com>
On Wed, 2012-11-14 at 08:43 -0600, Seth Bollinger wrote:
> Add bold color output to log level name and standard color output to
> log msg
> when bitbake is run from an iteractive console. Color output is only
> enabled
> if the terminal supports color.
>
> Used Jason Wessel's recommendation for transparency on verbose, note
> and plain.
>
This works much better. I've realised the escape sequences are ending up
in logfiles like the cooker log though so some further tweaking is
needed...
Also, your patches are coming through linewrapped so I have to fix them
manually before applying.
Cheers,
Richard
> Signed-off-by: Seth Bollinger <seth.boll@gmail.com>
> ---
> bitbake/lib/bb/msg.py | 40
> ++++++++++++++++++++++++++++++++++++++++
> bitbake/lib/bb/ui/knotty.py | 6 +++++-
> 2 files changed, 45 insertions(+), 1 deletions(-)
>
>
> diff --git a/bitbake/lib/bb/msg.py b/bitbake/lib/bb/msg.py
> index 9b39325..68b2ad7 100644
> --- a/bitbake/lib/bb/msg.py
> +++ b/bitbake/lib/bb/msg.py
> @@ -55,6 +55,25 @@ class BBLogFormatter(logging.Formatter):
> CRITICAL: 'ERROR',
> }
>
> + color_enabled = False
> + BASECOLOR, BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE
> = range(29,38)
> +
> + COLORS = {
> + DEBUG3 : CYAN,
> + DEBUG2 : CYAN,
> + DEBUG : CYAN,
> + VERBOSE : BASECOLOR,
> + NOTE : BASECOLOR,
> + PLAIN : BASECOLOR,
> + WARNING : YELLOW,
> + ERROR : RED,
> + CRITICAL: RED,
> + }
> +
> + BLD = '\033[1;%dm'
> + STD = '\033[%dm'
> + RST = '\033[0m'
> +
> def getLevelName(self, levelno):
> try:
> return self.levelnames[levelno]
> @@ -67,6 +86,8 @@ class BBLogFormatter(logging.Formatter):
> if record.levelno == self.PLAIN:
> msg = record.getMessage()
> else:
> + if self.color_enabled:
> + self.colorize(record)
> msg = logging.Formatter.format(self, record)
>
> if hasattr(record, 'bb_exc_info'):
> @@ -75,6 +96,25 @@ class BBLogFormatter(logging.Formatter):
> msg += '\n' + ''.join(formatted)
> return msg
>
> + def colorize(self, record):
> + color = self.COLORS[record.levelno]
> + if self.color_enabled and color is not None:
> + record.levelname = "".join([self.BLD % color,
> record.levelname, self.RST])
> + record.msg = "".join([self.STD % color, record.msg,
> self.RST])
> +
> + def enable_color(self):
> + import curses
> + try:
> + win = None
> + win = curses.initscr()
> + if curses.has_colors():
> + self.color_enabled = True
> + except:
> + pass
> + finally:
> + if win is not None:
> + curses.endwin()
> +
> class BBLogFilter(object):
> def __init__(self, handler, level, debug_domains):
> self.stdlevel = level
> diff --git a/bitbake/lib/bb/ui/knotty.py b/bitbake/lib/bb/ui/knotty.py
> index b99a121..d9aa973 100644
> --- a/bitbake/lib/bb/ui/knotty.py
> +++ b/bitbake/lib/bb/ui/knotty.py
> @@ -238,12 +238,16 @@ def main(server, eventHandler, tf =
> TerminalFilter):
> helper = uihelper.BBUIHelper()
>
> console = logging.StreamHandler(sys.stdout)
> - format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
> + format_str = "%(levelname)s: %(message)s"
> + format = bb.msg.BBLogFormatter(format_str)
> + if interactive:
> + format.enable_color()
> bb.msg.addDefaultlogFilter(console)
> console.setFormatter(format)
> logger.addHandler(console)
> if consolelogfile:
> bb.utils.mkdirhier(os.path.dirname(consolelogfile))
> + format = bb.msg.BBLogFormatter(format_str)
> consolelog = logging.FileHandler(consolelogfile)
> bb.msg.addDefaultlogFilter(consolelog)
> consolelog.setFormatter(format)
> --
> 1.7.2.5
>
>
>
>
> On Wed, Nov 14, 2012 at 7:22 AM, Richard Purdie
> <richard.purdie@linuxfoundation.org> wrote:
> On Wed, 2012-11-14 at 07:18 -0600, Seth Bollinger wrote:
> > Thanks! I've tested this and it works on my dark color
> scheme (it's
> > better actually :)). I also tested on white and it looks
> fine. If
> > Richard is ok with this solution, I'll make the changes and
> submit
> > another patch.
> >
> It sounds promising, I would like to try the patch...
>
> Cheers,
>
> Richard
>
>
>
>
>
next prev parent reply other threads:[~2012-11-14 23:40 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-11 15:17 [PATCH v2] bitbake: Colorize knotty interactive console output Seth Bollinger
2012-11-11 22:54 ` Chris Larson
2012-11-12 2:02 ` Seth Bollinger
2012-11-12 2:24 ` Chris Larson
2012-11-13 14:23 ` Richard Purdie
2012-11-13 14:45 ` Seth Bollinger
2012-11-13 15:22 ` Richard Purdie
2012-11-13 22:36 ` Jason Wessel
2012-11-14 13:18 ` Seth Bollinger
2012-11-14 13:22 ` Richard Purdie
2012-11-14 14:43 ` Seth Bollinger
2012-11-14 23:26 ` Richard Purdie [this message]
[not found] ` <CA+JN8xN-vkLxtd+J4BZoQ39xs3Yujh-J=CQ8q+T1k0r-t-bpzA@mail.gmail.com>
2012-11-16 14:45 ` Seth Bollinger
2012-11-22 3:36 ` Robert Yang
2012-11-25 21:37 ` Richard Purdie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1352935577.3709.7.camel@ted \
--to=richard.purdie@linuxfoundation.org \
--cc=bitbake-devel@lists.openembedded.org \
--cc=seth.boll@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.