Note that there are some explanatory texts on larger screens.

plurals
  1. POLogging error to stderr and debug, info to stdout with log4j
    primarykey
    data
    text
    <p>I want to add logging to an application I am developing, using apache log4j. At this point I want to redirect all log messages for level INFO and lower (TRACE, DEBUG) to stdout and all other log messages from WARN and above (ERROR, FATAL) to stderr. For example:</p> <pre class="lang-java prettyprint-override"><code>... logger.info("Processing at some point"); // must be written to stdout logger.debug("Point x was processed"); // must be written to stdout logger.warn("Incorrect point config"); // must be written only to stderr logger.error("Exception occurred at point x"); // must be written only to stderr </code></pre> <p>So what should be my log4j.properties file? Here how it looks at this momment:</p> <pre class="lang-sh prettyprint-override"><code>log4j.rootLogger=DEBUG, stdout, stderr # configure stdout # set the conversion pattern of stdout # Print the date in ISO 8601 format log4j.appender.stdout = org.apache.log4j.ConsoleAppender log4j.appender.stdout.Threshold = DEBUG log4j.appender.stdout.Target = System.out log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern = %-5p %d [%t][%F:%L] : %m%n # configure stderr # set the conversion pattern of stdout # Print the date in ISO 8601 format log4j.appender.stderr = org.apache.log4j.ConsoleAppender log4j.appender.stderr.Threshold = WARN log4j.appender.stderr.Target = System.err log4j.appender.stderr.layout = org.apache.log4j.PatternLayout log4j.appender.stderr.layout.ConversionPattern = %-5p %d [%t][%F:%L] : %m%n </code></pre> <p>The problem with the above configuration is that the logger.error() ... is printed at stdout too.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload