logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: [v2] Color console events per level
Date Thu, 01 Nov 2012 12:05:22 GMT
Great. Thanks for the pointers.


On Nov 1, 2012, at 2:23, Ralph Goers <ralph.goers@dslextreme.com> wrote:

The coloring isn't done by the layout but by the StylePatternConverter and
the HighlightPatternConverter. Rather than creating a new converter you can
simply enhance the HighlightPatternConverter to accept the styling. So in
addition to being able to do

<pattern>%d %highlight{%p} %style{%C{1.} [%t] %m}{bold,green}%n</pattern>

you could also do

<pattern>%d %highlight{%p}{FATAL=magenta bold, ERROR=red, WARN=yellow bold,
INFO=green} %style{%C{1.} [%t] %m}{bold,green}%n</pattern>


On Oct 31, 2012, at 7:40 PM, Gary Gregory wrote:

Hi All:

Nice job getting JAnsi support in Log4J2!

I have a custom appender I use for 1.2 to color whole lines based on the
level with some sensible defaults the use can override. For example:

log4j.appender.ColorConsole.layout.ConversionPattern=%d{ISO8601} [%t] %-5p:


log4j.appender.ColorConsole.FatalColor=//bold magenta
log4j.appender.ColorConsole.ErrorColor=//bold red
log4j.appender.ColorConsole.WarnColor=//bold yellow
log4j.appender.ColorConsole.TraceColor=//bold black

To do this a la log4j (1 and 2) though, it seems that the work should be
done in the layout and not in the appender.

But right now, I do not see a way to color the whole line (or part of a
line for that matter) based on the level for a given event.

I can do fancy formatting like:

      <PatternLayout pattern="%style{%d{ ISO8601 }}{black}
%style{[%t]}{blue} %style{%-5level:}{yellow}
%style{%msg%n%throwable}{green}" />

But that's not what I want. So I am considering putting more smarts in

Does that seem sensitive?

What should the configuration look like and how would you let it use
defaults if some levels are not matched with colors?

How about a new converter called level-style? For example:

Use default colors:

<PatternLayout pattern="%level-style{%d{ ISO8601 } [%t] %-5level:
%msg%n%throwable}" />

Use custom colors:

<PatternLayout pattern="%level-style{%d{ ISO8601 } [%t] %-5level:
%msg%n%throwable}{FATAL=magenta bold, ERROR=red, WARN=yellow bold,
INFO=green}" />

Your thoughts please.


E-Mail: garydgregory@gmail.com | ggregory@apache.org
JUnit in Action, 2nd Ed: <http://goog_1249600977/>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

View raw message