tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Johle <djo...@industrialinfo.com>
Subject Re: Issues Logging wtith log4j at common and webapp levels
Date Mon, 03 Dec 2012 18:57:08 GMT
Well I managed to accomplish my goal 100% with the help of some new 
features in Log4j 2.x (currently beta-3).

My eventual setup was to use the BasicContextSelector to ensure only 
a single logging heirarchy was created for the whole VM regardless of 
webapps.  Then I tag events per-webapp using a ServletFilter to 
manipulate the ThreadContext, and send them all through a central 
RoutingAppender which in turn directs the entries (based on the tag) 
to the appropriate FileAppender.

Since the tagging is done at the request level, both webapp specific 
classes, central libraries, and even VM-wide singletons used by a 
request all carry that tag (it uses ThreadLocal internally) and thus 
get routed properly.

As for the remaining System.out calls in JSP files, separate Loggers 
are defined for those to capture the events created by swallowOutput 
(which don't carry the tag) and manually route them the appropriate 
FileAppender.  Eventually that extra fluff can go away though.

Another nice part about this is I only have a single instance of the 
logj4 libraries & a single centralized configuration file, which is A 
Good Thing(tm) for this setup.

Lots of other features in log4j2 that I was able to benefit from as 
well like dynamic reconfiguration and such, so I also set up my 
internal Tomcat logging (read: anything without a tag) to route into 
Tomcat's log.  Sorry JULI, you just weren't good enough for me ;)



On 02/10/2012 20:29, Mark Thomas wrote:
>Thanks for the clear question. While it was quite long, it was very
>readable, relevant and on point. That meant I got to the end rather than
>giving up after a few lines which is what usually happens with me and
>long questions.
>
>
> > So in summary, I'm just trying to get shared libraries to have their
> > log4j-based logging written to the webapp-specific log files of the
> > calling webapp.  Is this possible?  If so, what's the trick?
>
>It can be done - with some caveats. Tomcat does this with Jasper.
>
>The short version is:
>- The loggers can not be static
>- There must be an instance of the class per web-app.
>
>If you have singletons and an instance per webapp doesn't make sense
>then the only option that comes to mind (after not much thinking) is
>that you need to pass the logger to the singleton rather than it using
>its own.
>
>HTH,
>Mark





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message