logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Goers <ralph.go...@dslextreme.com>
Subject Re: log4j-2.0 questions
Date Thu, 30 Jun 2011 13:47:59 GMT
The path I took was to get the actual Class object of the caller of getLogger (not just the
class's name) and then to see if the class's ClassLoader is the Thread Context ClassLoader.
If it is then it should use the LoggerContext for the application. If not, then it should
use a parent LoggerContext that is stored as a static in the context selector. In Tomcat this
all works perfectly. If the Log4J2 Core jar is in Tomcat's lib directory, when the webapp
is undeployed the application's LoggerContext will be released but the parent LoggerContext
will remain. If the Log4J2 Core jar is in the application then the application won't need
to be configured to have its own LoggerContext and will just use the static LoggerContext
that is part of the application, so that works correctly too.

Unfortunately, when you get to an app server with EAR's you add an extra level. In that case
the log4j jars might be part of the ear or they might still be in they app server's lib directory.
 In an EAR the application probably expects to be able to share a logging configuration for
all the WARs and EJBs in the EAR, so using the ThreadContext ClassLoader may not yield the
desired outcome.  Furthermore, different app servers use different ClassLoader strategy's
so I'm not even sure it is possible to create a one-size fits all solution for that.  You
may be right that it could be possible to implement a strategy for each container though.

As far as determining whether to log at all, I'm not really sure I understand what you are
referring to. One of the primary goals of a logging framework is to incur minimal overhead
when logging is disabled. I have a unit test specifically for that - it calls the isDebugEnabled
method 10 million times to verify that the performance is acceptable. It has to make so many
calls because the cost of a single call ends up being about 3 nanoseconds.


On Jun 30, 2011, at 12:14 AM, Mark Struberg wrote:

> Hi Ralph!
> Yes, the static loggers would be important to solve. It's just not acceptable that a
client library needs to take care of this problem
> That's why I thought that there are different strategy implementations:
> * OSGi
> * TCCL
> * JNDI (which is imo pain slow)
> The problem here is that we also need this info to determine if we should log at all,
so it really gets executed with each and every log.debug and log.trace too. But most times
it's the users (=programmers) fault. Doing 10 millions of log.debug per second in a proxy
is just not sane ;)
> Maybe we could pickup this logger-strategy only if the configuration is in the same classloader
or in a higher-level classloader?
> It should be possible to implement own strategies which could be used by app-servers
like JBoss to adopt it to their classloading strategy.
> makes sense?
> LieGrue,
> strub
> --- On Thu, 6/30/11, Ralph Goers <ralph.goers@dslextreme.com> wrote:
>> From: Ralph Goers <ralph.goers@dslextreme.com>
>> Subject: Re: log4j-2.0 questions
>> To: "Log4J Developers List" <log4j-dev@logging.apache.org>
>> Date: Thursday, June 30, 2011, 12:33 AM
>> OK - that is what I thought.  I
>> have the innards of that working now and have a decent
>> solution for Tomcat. But I need to do more work on it as the
>> way the various app containers handle ears makes that a bit
>> of a pain and for that I expect JNDI may be the only good
>> solution. I also don't use EJBs at all so I don't have
>> support for that yet, although my understanding is that EJB
>> 3 provides some features that could help in this.
>> FWIW, I've also considered the "unsolvable" problem of
>> static loggers that come from classes in parent
>> classloaders. I actually have something that will work quite
>> nicely in Tomcat but almost certainly won't work in JBoss or
>> other app servers, again due to the various ways those
>> containers deal with class loaders for enterprise
>> applications.  I took a look at JULI last night and
>> Tomcat is doing some interesting things in there but I think
>> what they are doing may only work in Tomcat.
>> Ralph
>> On Jun 29, 2011, at 3:40 PM, Mark Struberg wrote:
>>> [X] to have their own configuration
>>> In fact this is only needed for 'shared' libraries
>> like OpenWebBeans, MyFaces, OpenJPA, OpenEJB and stuff.
>> Basically all things which comes as part of a container. But
>> in that case it would be really nice ;)
>>> Ideally one could provide a configuration of packages
>> which are 'shared'.
>>> LieGrue,
>>> strub
>>> --- On Tue, 6/21/11, Ralph Goers <ralph.goers@dslextreme.com>
>> wrote:
>>>> From: Ralph Goers <ralph.goers@dslextreme.com>
>>>> Subject: Re: log4j-2.0 questions
>>>> To: "Log4J Developers List" <log4j-dev@logging.apache.org>
>>>> Date: Tuesday, June 21, 2011, 7:15 AM
>>>> On Jun 20, 2011, at 10:52 PM, Mark Struberg
>> wrote:
>>>>> Hi Ralph!
>>>>> The problem is that this should be one of n
>>>> 'pluggable' logger implementations. Because
>> getting the
>>>> current ContextClassLoader (for some servers you
>> even need
>>>> to do this via a doPrivileged block) can be
>> expensive.
>>>> Are you saying you want each webapp in a servlet
>> container
>>>> to use the same logging API but have different
>> backing
>>>> implementations or that they should each use the
>> same
>>>> implementation but be able to have their own
>> configuration
>>>> or something else?
>>>> The Log4J 2 API locates its implementation(s) by
>> finding
>>>> all the instances of
>> META-INF/log4j-provider.xml.  At
>>>> the moment it expects to find just one. I haven't
>> really
>>>> figured out what it should do if there is more
>> than one
>>>> implementation.  But I'm still not sure if
>> that is what
>>>> you are talking about (hence my question
>> above).  I
>>>> guess what I'm asking is if what Logback is doing
>> is
>>>> sufficient or if you think there is something else
>> that
>>>> needs to be done as I don't believe SLF4J or
>> Logback do
>>>> anything in doPrivileged blocks and I don't
>> believe Log4j
>>>> 1.x does either.  From the way I understand
>> that
>>>> Logback handles this is that it looks for the
>> implementation
>>>> on the current Threads ContextClassLoader and if
>> that fails
>>>> then it uses the ClassLoader of the class doing
>> the loading.
>>>> I've pretty much planned on doing the same thing.
>>>> Ralph
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org

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

View raw message