[
https://issues.apache.org/jira/browse/LOG4J2-784?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14110367#comment-14110367
]
Remko Popma commented on LOG4J2-784:
------------------------------------
I see your point and I appreciate the principle of least surprise.
For the below I assume you have read this [brief description of the
problem|http://logging.apache.org/log4j/2.x/manual/async.html#Location].
I agree that the current solution is not ideal: ideally the async
logger/appender should be able to figure out automatically whether location
information will be required downstream and automatically decide whether to
take the stack snapshot or not.
In practice this ideal solution is not easy to achieve: an async
logger/appender would need to inspect all the configured layouts, determine
whether this layout is actually used (not filtered out) and then determine
whether the layout requires location information. I'm not sure if this could be
made to work reliably for the built-in layouts, let alone custom layouts
created by users as log4j plugins...
Making includeLocation="true" the default as you propose would have a large
performance impact. One of the reasons we chose the current default is that we
assume users choose asynchronous logging because of the performance benefits.
So we should be as fast as possible out of the box.
Another reason: I assume most users are in a hurry to get things done. They
won't always read the documentation, so they will make mistakes. It is much
easier to detect that there is something wrong if you don't see the location
information that you expected to see in the log. It is harder to detect that
logging is dragging down your app's performance because you did not realize
includeLocation needs to be switched off.
Finally, both log4j-1.2 and logback use a similar mechanism (log4j1 calls it
"locationInfo", logback calls it
"[includeCallerData|http://logback.qos.ch/manual/appenders.html#AsyncAppender]")
where the user specifies in configuration whether a stack snapshot should be
taken for each log event. By default both log4j1 and logback do not include
location/caller. So log4j2 is consistent with log4j1 and logback.
I hope this helps.
> AsyncLoggers and PatternLayout with class/method/line
> -----------------------------------------------------
>
> Key: LOG4J2-784
> URL: https://issues.apache.org/jira/browse/LOG4J2-784
> Project: Log4j 2
> Issue Type: Bug
> Components: Layouts
> Affects Versions: 2.0.1
> Environment: OSX/Win7 64b, Java7/8, Eclipse/IDEA
> Reporter: Martin Vehovský
>
> Using slf4j binding.
> VM options:
> {{-DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector}}
> Appender:
> {code}
> <Console name="Console" target="SYSTEM_OUT">
> <PatternLayout pattern="%highlight{%p | %d{DEFAULT} | %t | %C{1}.%M(%L)
> | %m%n}{STYLE=Logback}"/>
> </Console>
> {code}
> Log message:
> DEBUG | 2014-08-18 19:05:13,795 | main | ?.() | HashSet: [A, B]
> Log message without the VM option "Log4jContextSelector":
> DEBUG | 2014-08-18 19:09:43,608 | main | Main.main(32) | HashSet: [A, B]
--
This message was sent by Atlassian JIRA
(v6.2#6252)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]