Bug 47357 - Declaring logger and category with same name causes closed appender error
Summary: Declaring logger and category with same name causes closed appender error
Status: NEW
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Configurator (show other bugs)
Version: 1.2
Hardware: PC Windows XP
: P2 minor
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-06-11 11:04 UTC by Bill DePhillips
Modified: 2009-06-11 11:05 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bill DePhillips 2009-06-11 11:04:42 UTC
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!");
	}

}