Logback different files for different levels - java

I have this appender in my logback.xml
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>logFile.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>logFile.%d{yyyy-MM-dd}.log</FileNamePattern>
<maxHistory>5</maxHistory>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{35} - %msg%n</Pattern>
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="FILE" />
</root>
So at the moment I am saving all my logs to one file. How can I make it like, one file saves only error logs and other saves all other?
And I want to keep using only 1 instance of logger in my code, something like this:
private static final Logger log = LoggerFactory.getLogger(Main.class);

Started looking for logback categories, found filters.
Just add filter description to your appender:
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>

This is what I do for Jboss but I guess you'll get the solution.
Create a dedicated appender for error.log as follows,
<appender name="ErrorFile" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/error.log"/>
<param name="Threshold" value="ERROR"/>
<param name="Append" value="false"/>
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<!-- Rollover at the top of each hour
<param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
-->
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
<!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
Create an appender for the rest of them
<appender name="File" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="Threshold" value="ALL"/>
<param name="Append" value="false"/>
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<!-- Rollover at the top of each hour
<param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
-->
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
<!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
-->
</layout>
</appender>
Then create specific categories for both the above
<category name="your_file_name/package_name">
<priority value="ERROR"/>
<appender-ref ref="ErrorFILE"/>
</category>
<category name="your_file_name/package_name">
<priority value="ALL"/>
<appender-ref ref="File"/>
</category>

Related

log4j issue: redirect logg to many files

Actually i am using log4j 1.2 with an xml configration file;
Is it possible to redirect the log of each class in a specified file; i want to logg in 3 files.
<appender name="file" class="org.apache.log4j.FileAppender" >
<!-- <param name="Threshold" value="INFO" /> -->
<param name="File" value="log/archive.log" />
<param name="Append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss}] %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<appender name="file" class="org.apache.log4j.FileAppender" >
<!-- <param name="Threshold" value="INFO" /> -->
<param name="File" value="log/check.log" />
<param name="Append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss}] %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="DEBUG" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %c{1}: %m [%L]%n" />
</layout>
</appender>
<logger name="org.apache.axis">
<level value="DEBUG"/>
</logger>
<root>
<priority value ="DEBUG"/>
<appender-ref ref="file" />
<appender-ref ref="console" />
</root>
you can file solution with log4j: Log output of a specific class to a specific appender

log4j logs everything regardless of the root level

We have some standalone java applications that log information to log files, with log4j (it's an old version : 1.2.8).
We have set the root level to ERROR, and defined several appenders, depending on the calling module.
The odd thing is that everything is logged, regardless of the level (INFO, DEBUG, etc.). We then decided to add the -Dlog4j.debug option to the java command line to find out if there wasn't a faulty log4.xml file being loaded, and then we saw this :
log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader#64c3c749.
log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader#64c3c749 class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader#64c3c749.
log4j: Trying to find [log4j.properties] using sun.misc.Launcher$AppClassLoader#64c3c749 class loader.
log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [null].
Why does log4j log everything, even if the root level is set to ERROR, and how can the configuration be loaded while it seems that it cannot be found?
EDIT :
1) Yes, everything is logged to the correct appenders, with the correct format and file names.
2) The log4j.xml is inside a jar, specified in the classpath.
Here is the log4j.xml:
<!-- Definition des appenders par niveau de log -->
<appender name="all" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${REP_LOG_OPE}/CA_ARBOR2010_ALL.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="80000KB"/>
<param name="MaxBackupIndex" value="2000"/>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="levelToMatch" value="ERROR"/>
</filter>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd/MM/yy - HH:mm:ss,SSS} | %-1p | %c | %L | %m%n" />
</layout>
</appender>
<appender name="debug" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${REP_LOG_OPE}/CA_ARBOR2010_DEBUG.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="80000KB"/>
<param name="MaxBackupIndex" value="2000"/>
<layout class="org.apache.log4j.SimpleLayout"/>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="levelToMatch" value="DEBUG"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd/MM/yy - HH:mm:ss,SSS} | %-1p | %c | %L | %m%n" />
</layout>
</appender>
<appender name="info" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${REP_LOG_OPE}/CA_ARBOR2010_INFO.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="80000KB"/>
<param name="MaxBackupIndex" value="2000"/>
<layout class="org.apache.log4j.SimpleLayout"/>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="levelToMatch" value="INFO"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd/MM/yy - HH:mm:ss,SSS} | %-1p | %c | %L | %m%n" />
</layout>
</appender>
<appender name="warn" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${REP_LOG_OPE}/CA_ARBOR2010_WARN.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="80000KB"/>
<param name="MaxBackupIndex" value="2000"/>
<layout class="org.apache.log4j.SimpleLayout"/>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="levelToMatch" value="WARN"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd/MM/yy - HH:mm:ss,SSS} | %-1p | %c | %L | %m%n" />
</layout>
</appender>
<appender name="error" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${REP_LOG_OPE}/CA_ARBOR2010_ERROR.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="80000KB"/>
<param name="MaxBackupIndex" value="2000"/>
<layout class="org.apache.log4j.SimpleLayout"/>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="levelToMatch" value="ERROR"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd/MM/yy - HH:mm:ss,SSS} | %-1p | %c | %L | %m%n" />
</layout>
</appender>
<appender name="fatal" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${REP_LOG_OPE}/CA_ARBOR2010_FATAL.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="80000KB"/>
<param name="MaxBackupIndex" value="2000"/>
<layout class="org.apache.log4j.SimpleLayout"/>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="levelToMatch" value="FATAL"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd/MM/yy - HH:mm:ss,SSS} | %-1p | %c | %L | %m%n" />
</layout>
</appender>
<!-- Definition des appenders specifiques -->
<!-- MVNO 2012 -->
<appender name="mvno2012" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${REP_LOG_OPE}/CA_MVNO2012.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="80000KB"/>
<param name="MaxBackupIndex" value="2000"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd/MM/yy - HH:mm:ss,SSS} | %-1p | %c | %t | %L | %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="levelMin" value="DEBUG"/>
<param name="levelMax" value="FATAL"/>
</filter>
</appender>
<!-- Moteur de collecte -->
<appender name="engine_collecte" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${REP_LOG_OPE}/CA_COLLECTE_ENGINE.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="80000KB"/>
<param name="MaxBackupIndex" value="2000"/>
<layout class="org.apache.log4j.SimpleLayout"/>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="levelMin" value="DEBUG"/>
<param name="levelMax" value="FATAL"/>
</filter>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd/MM/yy - HH:mm:ss,SSS} | %-1p | %c | %t | %L | %m%n" />
</layout>
</appender>
<!-- Utilitaires apache (org.apache ...) -->
<appender name="apache_utilities" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${REP_LOG_OPE}/CA_APACHE_UTILITIES.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="80000KB"/>
<param name="MaxBackupIndex" value="2000"/>
<layout class="org.apache.log4j.SimpleLayout"/>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="levelMin" value="DEBUG"/>
<param name="levelMax" value="FATAL"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd/MM/yy - HH:mm:ss,SSS} | %-1p | %c | %L | %m%n" />
</layout>
</appender>
<appender name="aruba" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${REP_LOG_OPE}/CA_ARUBA.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="80000KB"/>
<param name="MaxBackupIndex" value="2000"/>
<layout class="org.apache.log4j.SimpleLayout"/>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="levelMin" value="DEBUG"/>
<param name="levelMax" value="FATAL"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd/MM/yy - HH:mm:ss,SSS} | %-1p | %c | %L | %m%n" />
</layout>
</appender>
<appender name="fx" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${REP_LOG_OPE}/CA_FX.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="80000KB"/>
<param name="MaxBackupIndex" value="2000"/>
<layout class="org.apache.log4j.SimpleLayout"/>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="levelMin" value="DEBUG"/>
<param name="levelMax" value="FATAL"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd/MM/yy - HH:mm:ss,SSS} | %-1p | %c | %L | %m%n" />
</layout>
</appender>
<appender name="tuxedo" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${REP_LOG_OPE}/CA_TUXEDO.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="80000KB"/>
<param name="MaxBackupIndex" value="2000"/>
<layout class="org.apache.log4j.SimpleLayout"/>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="levelMin" value="DEBUG"/>
<param name="levelMax" value="FATAL"/>
</filter>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd/MM/yy - HH:mm:ss,SSS} | %-1p | %c | %L | %m%n" />
</layout>
</appender>
<appender name="arbor2010" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${REP_LOG_OPE}/CA_ARBOR2010.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="80000KB"/>
<param name="MaxBackupIndex" value="2000"/>
<layout class="org.apache.log4j.SimpleLayout"/>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="levelMin" value="DEBUG"/>
<param name="levelMax" value="FATAL"/>
</filter>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd/MM/yy - HH:mm:ss,SSS} | %-1p | %c{1} | %L | %X{ID} | %m%n" />
</layout>
</appender>
<logger name="com.ours.theirs.arbor2010" additivity="false">
<appender-ref ref="arbor2010"/>
</logger>
<logger name="com.ours.theirs.mvno2012" additivity="false">
<appender-ref ref="mvno2012"/>
</logger>
<logger name="com.csgsystems" additivity="false">
<appender-ref ref="aruba"/>
</logger>
<logger name="terrapin" additivity="false">
<appender-ref ref="tuxedo"/>
</logger>
<logger name="com.csgsystems.fx" additivity="false">
<appender-ref ref="fx"/>
</logger>
<logger name="com.ours.collecte" additivity="true">
<appender-ref ref="engine_collecte"/>
</logger>
<logger name="com.ours.common" additivity="false">
<appender-ref ref="engine_collecte"/>
</logger>
<logger name="org.apache" additivity="false">
<appender-ref ref="apache_utilities"/>
</logger>
<root>
<level value="ERROR"/>
<appender-ref ref="all"/>
</root>
EDIT 2 :
I still haven't found what's happening, but here is what I have found out and done so far :
1) The log4j.xml file was malformed : it was missing the DOCTYPE, there were multiple layouts, some layout classes were incorrect.
2) I have specified the path to the log4j.xml file in the command line
3) There were several calls to DOMConfigurator and PropertyConfigurator, I've removed them.
I have narrowed my research to a class that creates dynamic log files based on a thread id. Before the code in that class is executed, the log4j console logs clearly states the log level is ERROR. The moment the dynamic log files are created, the log level switches to DEBUG.
The answer is near.
EDIT 3
I've found the culprit!
A third party component loads its own log4j configuration on top of ours. It adds appenders and it changes the root logging level.
It's good to note that when a new file is loaded, log4j doesn't seem to debug that information to the console.
The root level was changed by a third party component, which loads a specific configuration.
When facing such a problem :
Check if your code doesn't contain any extra log4j dynamic configuration loading (DOMConfigurator, PropertyConfigurator)
Check if any third party component doesn't load any extra log4j configuration
Make sure your log4j.xml (or log4j.properties) is valid.

Log4j how to log by level and the log file should contains only its level's log [duplicate]

I am using log4j for logging in my applicaion. I am trying to different level logs in different files but something going wrong. Any help regrading this issue will be highly appreciated.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %c{1} - %m%n"/>
</layout>
</appender>
<appender name="DEBUG" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="TCS_patch_9/log/retailer_debug.log" />
<param name="Threshold" value="DEBUG" />
<param name="MaxFileSize" value="2MB"/>
<param name="MaxBackupIndex" value="3"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p %c - %m%n"/>
</layout>
</appender>
<appender name="INFO" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="TCS_patch_9/log/retailer_info.log" />
<param name="Threshold" value="INFO" />
<param name="MaxFileSize" value="2MB"/>
<param name="MaxBackupIndex" value="3"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p %c - %m%n"/>
</layout>
</appender>
<appender name="ERROR" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="TCS_patch_9/log/retailer_error.log" />
<param name="Threshold" value="ERROR" />
<param name="MaxFileSize" value="2MB"/>
<param name="MaxBackupIndex" value="3"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p %c - %m%n"/>
</layout>
</appender>
<appender name="FATAL" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="TCS_patch_9/log/retailer_repeat_delay.log" />
<param name="Threshold" value="FATAL" />
<param name="MaxFileSize" value="2MB"/>
<param name="MaxBackupIndex" value="3"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-5p %c - %m%n"/>
</layout>
</appender>
<root>
<priority value ="error" />
<appender-ref ref="console"/>
<appender-ref ref="DEBUG"/>
<appender-ref ref="INFO"/>
<appender-ref ref="ERROR"/>
<appender-ref ref="FATAL"/>
</root>
</log4j:configuration>
The standard behaviour for log4j appenders is that they log all messages at their threshold level or higher, i.e. an appender with threshold INFO will log INFO, WARN, ERROR and FATAL messages but not DEBUG. If you want to log only INFO messages but not WARN and above then you need to use a LevelMatchFilter.
You will also need to set your root logger priority to DEBUG, otherwise it will only send ERROR and FATAL messages to its appenders and your DEBUG and INFO files will be empty.

log4j writing to rolled over file

We have set log4j rollover as 500mb upon 500 mb it is creating a file new file log.1 but still it is sometimes writing to log.1 and to log and sometimes only to log and some times to log.1.
I am using apache tomcat.
It is so inconsistent.
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p: %c - %m%n" />
</layout>
</appender>
<appender name="file" class="org.apache.log4j.RollingFileAppender">
<param name="maxFileSize" value="500MB" />
<param name="maxBackupIndex" value="5" />
<param name="Append" value="true"/>
<param name="File" value="c:/logs/web.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %p [%c] - %m%n" />
</layout>
</appender>
Could you please let me know any reason for this?
Regards,
Adam

Log4j rolling file size

I have a xml log4j configuration file like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="CA" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="KTS %5p [%F] - %m%n"/>
</layout>
</appender>
<appender name="EXCEPTION" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="C:\\exception.log"/>
<param name="MaxFileSize" value="20MB"/>
<param name="MaxBackupIndex" value="5"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd-MM-yyyy HH:mm:ss,SSS} KTS %5p [%F] - %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="LevelToMatch" value="ERROR"/>
<param name="AcceptOnMatch" value="true"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"/>
</appender>
<appender name="TIMER" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="C:\\timer.log"/>
<param name="MaxFileSize" value="20MB"/>
<param name="MaxBackupIndex" value="5"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd-MM-yyyy HH:mm:ss,SSS} KTS %5p [%F] - %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="LevelToMatch" value="INFO"/>
<param name="AcceptOnMatch" value="true"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"/>
</appender>
<root>
<level value="debug"/>
<appender-ref ref="CA"/>
<appender-ref ref="TIMER"/>
<appender-ref ref="EXCEPTION"/>
</root>
</log4j:configuration>
The problem I'm having is that the file's size are passing que established file size...
Any ideas why this might be happening?
Try to append log4j:configuration attribute for debug.
For example.
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
<!-- something -->
</log4j:configuration>
Debug information is written to console.
Can you try assigning MaxBackupIndex first andMaxFileSize` later . If that configuration works
<appender name="TIMER" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="C:\\timer.log"/>
<param name="MaxBackupIndex" value="5"/>
<param name="MaxFileSize" value="20MB"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd-MM-yyyy HH:mm:ss,SSS} KTS %5p [%F] - %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="LevelToMatch" value="INFO"/>
<param name="AcceptOnMatch" value="true"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"/>
</appender>
Sorry, but I already solved this issue and forgot to put the response here.
The problem was beacuse when I needed to restart the application, some threads were not being destroyed, locking the log file.
Thanks for your help anyway

Categories

Resources