9

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 ?

Laurent.B
  • 213
  • 2
  • 14
Vinoth Kumar C M
  • 10,378
  • 28
  • 89
  • 130

3 Answers3

20

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.

Pino
  • 7,468
  • 6
  • 50
  • 69
  • 1
    Wow. I had one duplicate logger and this problem had me stuck for over a day. I even read this post and didn't think this was my problem, but I just didn't check carefully enough. Man, you'd think there'd be some kind of warning. Thanks so much! – bdetweiler Aug 04 '16 at 16:09
  • can the problem also occur if a `` element & a `` element is linked to same appender – wildthing81 Jun 27 '17 at 07:20
10

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.

manikanta
  • 8,100
  • 5
  • 59
  • 66
4

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>
Swamy
  • 111
  • 1
  • 2
  • 15