[ 
https://issues.apache.org/jira/browse/LOG4J2-555?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13925443#comment-13925443
 ] 

Remko Popma commented on LOG4J2-555:
------------------------------------

The enums (like MsgBuilder) use the double-dispatch pattern as a clean way to 
avoid introducing a conditional. Avoiding a branch means the CPU doesn't need 
to do branch prediction (potential cache miss/pipeline stall).

The purpose of the refactoring in the patch was to
# reduce semi-duplicate code in many AbstractLogger methods 
# extract elements of the {{if(isEnabled(...){log(...);\}_}} pattern so these 
elements can be re-used in extended/custom loggers
# these reusable elements in turn make managing the FQCN less onerous for 
custom/extended loggers: these loggers don't need to repeat the  
{{if(isEnabled(...){log(...);\}_}} pattern but instead can have a one-line 
implementation that calls the {{doLog(...)}} method.

So to me, this patch solves the FQCN problem this ticket was created for. If we 
decide to reject this patch I don't mind not having a solution but just keeping 
things the way they are. I don't think the FQCN is a huge problem and I would 
not be in favor of much added complexity just to make FQCN easier to manage for 
the rare use case of custom/extended loggers. Any extra classes/interfaces 
should carry their own weight so to speak and have benefits other than FQCN, 
IMHO. 

Would the stream/writer loggers benefit from the patch attached here? (I 
haven't checked...)

> Location-based functionality broken in AbstractLoggerWrapper subclasses
> -----------------------------------------------------------------------
>
>                 Key: LOG4J2-555
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-555
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: API, Core
>    Affects Versions: 2.0-rc1
>            Reporter: Remko Popma
>            Assignee: Remko Popma
>             Fix For: 2.0-rc2
>
>         Attachments: LOG4J2-555-delegate.patch
>
>
> *How to reproduce*
> * Create a custom logger that extends {{AbstractLoggerWrapper}} (or generate 
> one with the tool attached to LOG4J2-519)
> * In the custom logger provide a public method that invokes the {{log(Level, 
> String)}} method
> * Configure a pattern layout that uses location, like %C for the logger FQCN
> * From a sample app, call the public method on your custom logger.
> * The output will show the class name of the custom logger instead of the 
> class name of the calling class in the sample application.
> *Cause*
> {{AbstractLogger}}'s FQCN field is {{static final}} and initialized to 
> {{AbstractLogger.class.getName()}}. Then, in 
> {{Log4jLogEvent#calcLocation()}}, when walking over the stack trace elements, 
> the element _following_ the FQCN is returned. So only loggers that directly 
> subclass from {{AbstractLogger}} will work correctly. Loggers that inherit 
> from {{AbstractLoggerWrapper}} are two levels removed from {{AbstractLogger}} 
> and the {{calcLocation()}} method will not work correctly.
> *Solution*
> I think {{AbstractLogger}}'s FQCN field should be made non-static, and 
> initialized to {{getClass().getName()}} in the constructor of 
> {{AbstractLogger}}. {{Log4jLogEvent#calcLocation()}} can then be modified to 
> return the {{StackElement}} whose class name matches the FQCN, instead of the 
> next element. Location-based functionality should then work for arbitrarily 
> deep subclass hierarchies of AbstractLogger.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org

Reply via email to