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

大兔子大兔子 提交于 2019-12-10 03:06:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!