0

I'm migrating from log4j 1.2 to log4j 2.0. Earlier all my console logs and logs were printed in specific log files. But after migrating, Console logs are printed in tomcat7-stderr.logs and other logs are printed in specific log file.

Is there a way I can print console logs also to the file I specified in log4j2.xml?

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="all">
<appenders>
    <Console name="STDOUT">
        <PatternLayout pattern="&lt;%X{UOWID}&gt; [%t] %d{yyyy/MMM/dd HH:mm:ss} %-5p [%c{1}] %m%n"/>
    </Console>
    <RollingFile name="fileAppender" fileName="${sys:catalina.base}/logs/omp-web-services.log" filePattern="${sys:catalina.base}/logs/omp-web-services.log">
        <PatternLayout pattern="&lt;%X{UOWID}&gt; [%t] %d{yyyy/MMM/dd HH:mm:ss} %-5p [%c{1}] %m%n" />
        <Policies>
            <SizeBasedTriggeringPolicy size="250 MB"/>
        </Policies>
    </RollingFile>
</appenders>
<loggers>
    <root level="INFO">
        <appenderRef ref="STDOUT" level="info"/>
        <appenderRef ref="fileAppender" level="info"/>
    </root>
</loggers>

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
Balaji
  • 1
  • 3
  • What file was your console log originally output to? Have you upgraded tomcat in the meantime? – Duncan Jones Apr 08 '14 at 07:48
  • console logs were printed on the same file mentioned in RollingFileAppender, i.e omp-web-services.log and I didnt update tomcat – Balaji Apr 08 '14 at 08:05
  • I find your requirements confusing. Why declare a console appender if you want the log statements to end up in a file? And why would you want them to end up in the same file as your other log statements - surely that would result in duplicate log entries? – Duncan Jones Apr 08 '14 at 08:16
  • I want the console logs to be in a seperate file, rather than tomcat.stderr.logs. And, printing the console logs along with the other log statements won't give duplicate entries, since both are different. – Balaji Apr 08 '14 at 08:22
  • Both appenders are attached to the root logger and have the same pattern. I struggle to see how they will produce different outputs. Are you wanting the console output to go to the console *and* a file or just a file. If the latter case, why are you using a console appender at all? – Duncan Jones Apr 08 '14 at 08:24

0 Answers0