Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j:ERROR Attempted to append to closed appender named [..]

Tags:

log4j

I am getting following errors on my console repeatedly

log4j:ERROR Attempted to append to closed appender named [ConsoleAppender].
log4j:ERROR Attempted to append to closed appender named [FixedWindowRollingFile].

used log4j.xml

<?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 class="org.apache.log4j.rolling.RollingFileAppender" name="FixedWindowRollingFile">
        <param name="Append" value="true"/>
        <param name="ImmediateFlush" value="true"/>

        <rollingPolicy class="org.apache.log4j.rolling.FixedWindowRollingPolicy">
            <param name="fileNamePattern" value="logs/StandardizeAccountService.%i.log"/>
            <param name="minIndex" value="1"/>
            <param name="maxIndex" value="10"/>
        </rollingPolicy>
        <triggeringPolicy class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
            <param name="MaxFileSize" value="1002400"/>
        </triggeringPolicy>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %p %c{1}:%L - %m%n"/>
        </layout>
    </appender>

    <appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.SimpleLayout"/>
    </appender>

    <logger name="com.arosys" additivity="false" >
        <level value="INFO" />
        <appender-ref ref="ConsoleAppender" />
        <appender-ref ref="FixedWindowRollingFile"/>
    </logger>

    <root>
        <priority value="INFO"/>
        <appender-ref ref="ConsoleAppender"/>
        <appender-ref ref="FixedWindowRollingFile"/>
    </root>
</log4j:configuration>

please help me where the problem.

like image 244
Sameek Mishra Avatar asked Nov 23 '11 13:11

Sameek Mishra


3 Answers

I got the same error:

log4j:ERROR Attempted to append to closed appender named [rollingFileAppender].

In my log4j.xml

I have two loggers with the same name like below

<logger name="java.sql.PreparedStatement" additivity="false">
    <level value="INFO"/>
    <appender-ref ref="rollingFileAppender"/>
</logger>

 <logger name="java.sql.PreparedStatement">
    <level value="INFO"/>
    <appender-ref ref="rollingFileAppender"/>
</logger>

I removed the duplicate, it worked.

like image 154
satti Avatar answered Sep 21 '22 21:09

satti


I've answered similar question here: https://stackoverflow.com/a/9973283/340290

In my case, I've two log4j.properties available to the Log4J: one via placing it in classpath and other being loaded programmatically (using PropertyConfigurator.configure(..)).

And in the two files, I've ConsoleAppender registered with same name stdout and used for same category twice (one per each properties file). Removing config or the properties file solved my issue.

like image 27
manikanta Avatar answered Sep 25 '22 21:09

manikanta


One could overwrite the configuration using:

BasicConfigurator.resetConfiguration();
PropertyConfigurator.configure(props);
like image 20
Mike Avatar answered Sep 25 '22 21:09

Mike