0

I have been trying to change the logging from console to both console as well as file. Looking at the large documentation on log4j I was able to add the appender as shown in the code below. However I don't seem to be getting logs in the specified file.

Any ideas what might be wrong? Here is my log4j.xml (already located at src/)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
        <param name="Threshold" value="DEBUG"/>
        <param name="Target" value="System.out"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
        </layout>
    </appender>
    <appender name="FILE" class="org.apache.log4j.RollingFileAppender">
        <param name="append" value="false" />
        <param name="file" value="/data/MFlogs/log.log"/>
        <param name="immediateFlush" value="true"/>
        <param name="threshold" value="debug"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
        </layout>
    </appender>


    <root>
        <priority value="DEBUG" />
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
    </root>

</log4j:configuration>
Ashwin
  • 1,190
  • 2
  • 10
  • 30

2 Answers2

0

change file path tag. try it with double slash. value="//data//MFlogs//log.log"

kavi temre
  • 1,321
  • 2
  • 14
  • 21
  • Why you are using xml file, you can do the same thing with properties file. in xml if there is a whitespace, it create problem. try to copy the content then delete it from xml , save the blank file again paste it and save. – kavi temre May 06 '15 at 04:10
  • everything looks fine in your xml, sometime eclipse/IDE didn't parse xml file, try to restart eclipse/IDE. – kavi temre May 06 '15 at 04:11
0

Try adding full path to path location or add ${catalina.home}/logs/myApp.log to it.

Read this question, it tells how to use relative path. It is easy if you use properties file instead of xml file.

Community
  • 1
  • 1
Maleen Abewardana
  • 13,600
  • 4
  • 36
  • 39