Hi i am new using log4j
I am trying to configure the xml to send those logging into the log file using the and appender, well, the appender works fine so i want to use appender so that it will clear the log file daily, but when it first created the log file, it doesn't write any log message into the file created by , so i come here to get some advise
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="FATAL" >
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="${pattern}" />
</Console>
<RollingFile name="rollingfile" fileName="rolling.log"
filePattern="rolling-%d{MM-dd-yyyy}.log">
<PatternLayout pattern="${pattern}" />
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>
</RollingFile>
<File name="file" fileName="test2.log">
<PatternLayout pattern="${pattern}" />
</File>
</Appenders>
<Loggers>
<Root level="trace" >
<AppenderRef ref="Console" />
<AppenderRef ref="rollingfile" />
<AppenderRef ref="file" />
</Root>
</Loggers>
</Configuration>
You have
AppenderRef="rolling"
, but your Appender is named "rollingfile". These need to match.Also, log4j probably issues a warning that there is a problem with the configuration. I recommend you specify
<Configuration status="WARN" >
at the start of your config instead of FATAL so that you can see these warnings.It may be that you need to specify
${sys:pattern}
to read the system property. Instead of the${pattern}
variable, first try an explicit pattern like%d %p [%t] %m%n
.