Bug 51784

Summary: logger adapter, delagate call to logging method
Product: Log4j - Now in Jira Reporter: luc peuvrier <lc.pvrr>
Component: OtherAssignee: log4j-dev <log4j-dev>
Status: NEW ---    
Severity: enhancement    
Priority: P2    
Version: 1.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description luc peuvrier 2011-09-08 02:55:25 UTC
In my project JOAFIP I wanted to be independant of the logging framework.
I use log4j by default because it is my preference and it is commonly used.
But not all project use log4j, so I wanted to be open to alternative.

This make me create an adapter, see attachment.
for example Logger.error(...) in my code is replaced by JoafipLogger.error(...) and JoafipLogger.error delegate to org.apache.log4j.Logger.error(...)

But I discovered using "[%5p] - %d [%t] (%c.java:%M:%L) %n %m%n%n" as conversion pattern that line number was wrong. So I created the attached code.

ideally a method Logger.setFQCN("net.sf.joafip.logger.JoafipLogger") would me able to solve the problem. But I have to write the attached code to have the issue.

What do you think to add Logger.setFQCN method ?
Comment 1 Curt Arnold 2011-09-09 04:54:54 UTC
An single instance of Logger is returned for any call to Logger.getLogger(). If there were multiple "wrapping" classes wrapping the same instance of Logger, they would be conflicting calls to setFQCN().

Is your wrapping class calling Logger.log(String callerFQCN, Priority level, Object message, Throwable t)  which is designed for this scenarios? If so, are you running into any problems.
Comment 2 luc peuvrier 2011-09-09 06:58:52 UTC
calling Logger.forcedLog(String callerFQCN, Priority level,Object message, Throwable t) to "wrap" the logger is not because of multiples wrapping class. There is only one proprietary logging class that delegate to log4j. I do not see any reason to have multiple class for one project, but we can imagine multiple project using the same approach, so it can exist more than one "wrapping" class. so use of Logger.setFQCN is not a good solution.
may be better to have addtionnal parameter to logger functions.