问题
What is meant by "Attempted to append to closed appender " ?
The following is a small part of my log4j.xml file
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="TRACE" />
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p: %m%n" />
</layout>
</appender>
<logger name="java.sql" additivity="false">
<level value="trace" />
<appender-ref ref="stdout" />
</logger>
I am trying to print some sql queries out , but I am getting the above error . Am I missing something ?
回答1:
I got this message when my log4j.xml contained, due to a copy-and-dont-edit, two loggers (aka categories) with the same name linked to the same appender.
回答2:
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 in each properties file). Removing config or the properties file solved my issue.
回答3:
In my case, I used 2 logger elements on same package name caught into this error. removing one of them solved the problem.
<logger name="org.activiti.engine" additivity="false">
<level value="error" />
<appender-ref ref="LOGFILE" />
</logger>
<logger name="org.activiti.engine" additivity="false">
<level value="debug" />
<appender-ref ref="activitiBPMLog" />
</logger>
来源:https://stackoverflow.com/questions/6017014/log4j-log4jerror-attempted-to-append-to-closed-appender-named-stdout