logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Okara <billok...@gmail.com>
Subject Re: is it possible to set container shared lib to use custom loggerContext
Date Tue, 26 Jul 2016 18:46:45 GMT
yeah, don't think changing the sharedLib code to select the context is
an option, as the sharedLib jars are mostly third-party ones (but good
to know how it can be done though, thanks!)

also good to know that the solution I'm using is not an unreasonable one...


Thanks again for the comments,
Bill

On Mon, Jul 25, 2016 at 5:17 PM, Remko Popma <remko.popma@gmail.com> wrote:
> I don't think it's possible to do this in configuration. In the sharedLib code, you can
obtain Loggers by calling LogManager.getContext(true).getLogger().
>
> I think that will force the specified Logger to live in a separate context from your
application. I wouldn't like hard-coding this in my library though...
>
> Your current solution allows most flexibility imho.
>
> Remko
>
> Sent from my iPhone
>
>> On 2016/07/26, at 3:56, Bill Okara <billokara@gmail.com> wrote:
>>
>> Hi Remko,
>>
>> thanks for the suggestion, that's actually what I am doing currently.
>> That is, listing the various class packages in the shared libs to be
>> logged to a common log file.
>>
>> But was trying to see if there's some more robust way to do that,
>> something like (maybe) specify/config which loggerContext the
>> parentClassloader should be assigned to?
>>
>> A common use case for that is, usually the JNDI resources will be put
>> in the container shared lib dir (as per tomcat's instruction), so
>> would be good if can config the container shared lib classloader
>> (parent of the webapp classloader) to use a logger context other than
>> the webapp logger context.
>>
>> Comment?
>>
>>
>> Thanks!
>> William
>>
>>
>>> On Mon, Jul 25, 2016 at 8:21 AM, Remko Popma <remko.popma@gmail.com> wrote:
>>> There may be other ways to do this, but if the classes in the sharedLib are
>>> in a specific package, you could configure the log4j2.xml configurations
>>> for both web apps to create a separate appender (and a separate log file)
>>> for the loggers for that package.
>>>
>>> Remko
>>>
>>>> On Sat, Jul 23, 2016 at 3:18 AM, Bill Okara <billokara@gmail.com> wrote:
>>>>
>>>> Hi,
>>>>
>>>> Following is my deployment env:
>>>>
>>>> tomcat7
>>>>    |- lib/sharedLib12.jar   // shared lib  used by webapp1 and webapp2
>>>>    |- lib/slf4j-api-1.7.7.jar, log4j-api-2.3.jar, log4j-core-2.3.jar,
>>>> log4j-slf4j-impl-2.3.jar
>>>>    |
>>>>    |- webapps
>>>>         |-webapp1/WEB-INF/classes/log4j2.xml
>>>>         |                                 lib/log4j-web-2.3.jar
>>>>         |-webapp2/WEB-INF/classes/log4j2.xml
>>>>         |                                 lib/log4j-web-2.3.jar
>>>>
>>>>
>>>> With servlet 3.0+ and default ClassLoaderContextSelector, it was
>>>> quite simple (awesome!) to config so that log output from each webapp
>>>> will be sent to it's own log file (webapp1.log, webapp2.log)
>>>>
>>>> But the problem is that log output from the sharedLib jar will always
>>>> goto to the first loaded webapp, because:
>>>> ----------> Parent Classloader:
>>>> org.apache.catalina.loader.StandardClassLoader@59717824
>>>>
>>>> the parent classloader (the one sharedLib is loaded) will be assigned
>>>> to the loggerContext of the first loaded webapp (which kinda makes
>>>> sense).
>>>>
>>>>
>>>> Question:
>>>> is there a way to config so that jars inside the tomcat/lib can be
>>>> logged to a common/separate logger context (or log file) that is
>>>> independent of the loaded webapp? (without configure tomcat to use
>>>> log4j2 as internal logger?)
>>>>
>>>>
>>>> Thanks!
>>>> Bill
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>

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


Mime
View raw message