title: Log4J: Redirect Stderr message to the main log file
body: <p>I have a cmd line tool we are deploying to the customer soon. I have a nasty StdErr message in appearing in the cmd window from a framework I'm consuming and I'm struggling to redirect that message to my log file with Log4J.</p>
  
  <p>Here is my log4j.xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"&gt; &lt;log4j:configuration debug="false" xmlns:log4j='http://jakarta.apache.org/log4j/'&gt;
  
      &lt;appender name="file" class="org.apache.log4j.RollingFileAppender"&gt;
          &lt;param name="append" value="false" /&gt;
          &lt;param name="maxFileSize" value="500MB" /&gt;
          &lt;param name="maxBackupIndex" value="5" /&gt;
          &lt;param name="file" value="test.log" /&gt;
          &lt;layout class="org.apache.log4j.PatternLayout"&gt;
              &lt;param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" /&gt;
          &lt;/layout&gt;
      &lt;/appender&gt;
  
      &lt;root&gt;
          &lt;level value="DEBUG" /&gt;
          &lt;appender-ref ref="file" /&gt;
      &lt;/root&gt;
  
  &lt;/log4j:configuration&gt;
  </code></pre>
  
  <p>I have googled around and I cant find anyone with a similar case to me.</p>
  
  <p>I have redirected it using the following lines but I'd rather redirect it with log4j so everything is in the same file</p>
  
  <pre><code>File file = new File("error.log");
  FileOutputStream fos = new FileOutputStream(file);
  PrintStream ps = new PrintStream(fos);
  System.setErr(ps);
  </code></pre>
  
  <p>I cant redirect it with JBoss or tomcat settings because I'm not using a container. It is a JAR directly on the CMD line.</p>
  
  <p>Note: I want STDOUT to still go to the CMD window as that is the menu system for the user.</p>