You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Laurent Hasson <ld...@CapsicoHealth.com> on 2017/06/19 12:55:08 UTC

StdErr and StdOut

Hello,

 

I used to use ANSI coloring for my logs, which was very nice to
differentiate between levels. However, performance became an issue when
using Eclipse: in our app, which uses logging copiously, the whole app
literally slows down by a factor of 4-5x when the ANSI plugin is used. That
makes our dev a pain in the neck. So I reluctantly removed the ANSI
%highlight{…} configuration.

 

However, Eclipse has this capability to show StdOut in regular color (black)
and StdErr in red. Is there a way to configure log4j2 so that ERR messages
go to STDERR in console mode?

 

Here is my configuration:

 

<?xml version="1.0" encoding="UTF-8"?>

<Configuration status="info">

       <Appenders>

              <Console name="Console" target="SYSTEM_OUT">

                     <PatternLayout>

                            <pattern>%highlight{%d{MMdd.HHmmss.SSS}#%-3t
%level{length=1} %15.15c{1}|  %m%ex{20}%n}</pattern>

                     </PatternLayout>

        </Console>

       </Appenders>

       <Loggers>

              <Root level="debug">

                     <AppenderRef ref="Console" />

              </Root>

       </Loggers>

</Configuration>

 

I tried a naïve solution doing

 

<?xml version="1.0" encoding="UTF-8"?>

<Configuration status="info">

       <Appenders>

              <Console name="Console" target="SYSTEM_OUT">

                     <PatternLayout>

                <pattern>%d{MMdd.HHmmss.SSS}#%-3t %level{length=1}
%15.15c{1}|  %m%ex{20}%n</pattern>

                     </PatternLayout>

        </Console>

              <Console name="ConsoleErr" target="SYSTEM_ERR">

                     <PatternLayout>

                <pattern>%d{MMdd.HHmmss.SSS}#%-3t %level{length=1}
%15.15c{1}|  %m%ex{20}%n</pattern>

                     </PatternLayout>

        </Console>

       </Appenders>

       <Loggers>

              <Root level="error">

                     <AppenderRef ref="ConsoleErr" />

              </Root>

              <Root level="debug">

                     <AppenderRef ref="Console" />

              </Root>

       </Loggers>

</Configuration>

 

 

But that didn’t work. All logs go to STDOUT, and if I reverse the order of
the Loggers definitions, all go to STDERR.

 

 

Laurent Hasson
Co-Founder and CTO

CapsicoHealth Inc.

 



Research has shown that capsaicin, the substance that gives hot red peppers
(or chilies) their kick, and boosts our metabolism, keeps immature fat cells
from developing into full-fledged ones. And a recent study found that a
compound in some sweet peppers (called CH-19 Sweet), which resembles
capsaicin, provides similar positive metabolic effects.