https://issues.apache.org/bugzilla/show_bug.cgi?id=47357
Summary: Declaring logger and category with same name causes
closed appender error
Product: Log4j
Version: 1.2
Platform: PC
OS/Version: Windows XP
Status: NEW
Severity: minor
Priority: P2
Component: Configurator
AssignedTo: [email protected]
ReportedBy: [email protected]
While looking into a production issue, I recently uncovered the following
inconsistency.
In log4j.properties, if you declare a logger twice:
log4j.rootCategory=FATAL, console
log4j.logger.ReproduceLog4jProblem=INFO,console
log4j.logger.ReproduceLog4jProblem=INFO,console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%p [(%c{3})] %m%n
There is no warning or strange behavior. If you declare a logger and a
category (in either order) with the same name like this:
log4j.rootCategory=FATAL, console
log4j.category.ReproduceLog4jProblem=INFO,console
log4j.logger.ReproduceLog4jProblem=INFO,console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%p [(%c{3})] %m%n
Then when you try to write to that log, the following error appears:
log4j:ERROR Attempted to append to closed appender named [console].
I understand that this is really a configuration error, but I believe that the
behavior should be the same in either case. But maybe an improvement would be
to display a warning when redefining any loggers or categories. Failing either
of those, is there a way to show a better error rather than closed appender?
Googling for that error message did not show anything related to duplicate
mixed logger and category configuration.
FYI this is the simple class I used to test this:
public class ReproduceLog4jProblem {
private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
.getLogger(ReproduceLog4jProblem.class);
public static void main(String[] args) {
LOG.info("Log!");
}
}
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]