Bug 50164 - getAppender method in Logger class doesn't return inherited appenders when using a configuration file
Summary: getAppender method in Logger class doesn't return inherited appenders when us...
Status: NEW
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Appender (show other bugs)
Version: 1.2
Hardware: PC Windows XP
: P2 normal
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-27 11:44 UTC by Lior Zimmerman
Modified: 2010-10-27 17:39 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lior Zimmerman 2010-10-27 11:44:38 UTC
Example; I will describe an easily reproduced configuration scheme:

Logger A contains appender1, appender2.
Logger A.B contains appender3.

When calling B.getAppender("appender1") we get a null pointer.
To verify this problem one can call Logger.getLogger("A.B").getAllAppenders() - only appender3 is being returned.
Comment 1 Ralph Goers 2010-10-27 17:11:15 UTC
This is strictly my opinion, but:
1. The bug here is that getAppender() is a public method on a logger. It is really an internal method used by Log4j that is exposed publicly due to the way Log4j was implemented and 2. This is the correct behavior. 

Log4j 1.2 calls getAppender for each Appender attached to the logger. After doing so, if the logger is "additive" it calls delegates to the parent's logger where the same process is followed until it either reaches a logger which isn't additive or processes the root logger.  The change you are requesting would cause log4j to process appenders differently than it currently does.
Comment 2 Lior Zimmerman 2010-10-27 17:39:57 UTC
Well, I find this behavior handy if you have a custom appender that needs to get some parameters manually.
For example, I can set the root logger to contain my custom appender, and then call getAppender("myCustomAppender") on each logger I register, and customize its parameters as I please.
But this is strictly my opinion, and for the record - I have no idea how complicated/efficient it will be to implement it, as I only shortly skimmed the relevant code segment of log4j's code.

> This is strictly my opinion, but:
> 1. The bug here is that getAppender() is a public method on a logger. It is
> really an internal method used by Log4j that is exposed publicly due to the way
> Log4j was implemented and 2. This is the correct behavior. 
> 
> Log4j 1.2 calls getAppender for each Appender attached to the logger. After
> doing so, if the logger is "additive" it calls delegates to the parent's logger
> where the same process is followed until it either reaches a logger which isn't
> additive or processes the root logger.  The change you are requesting would
> cause log4j to process appenders differently than it currently does.