Return-Path: X-Original-To: apmail-tomcat-users-archive@www.apache.org Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 382F6E43D for ; Mon, 3 Dec 2012 18:57:51 +0000 (UTC) Received: (qmail 20825 invoked by uid 500); 3 Dec 2012 18:57:47 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 20696 invoked by uid 500); 3 Dec 2012 18:57:47 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 20686 invoked by uid 99); 3 Dec 2012 18:57:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Dec 2012 18:57:47 +0000 X-ASF-Spam-Status: No, hits=3.3 required=5.0 tests=FAKE_REPLY_B,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of djohle@industrialinfo.com designates 65.89.208.41 as permitted sender) Received: from [65.89.208.41] (HELO pig.industrialinfo.com) (65.89.208.41) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Dec 2012 18:57:41 +0000 Received: from djohle-PC.industrialinfo.com (djohle.industrialinfo.com [10.243.0.42]) (authenticated bits=0) by pig.industrialinfo.com (42/42) with ESMTP id qB3IvJl4001373 for ; Mon, 3 Dec 2012 12:57:19 -0600 Message-Id: <201212031857.qB3IvJl4001373@pig.industrialinfo.com> X-Mailer: QUALCOMM Windows Eudora Version 7.1.0.9 Date: Mon, 03 Dec 2012 12:57:08 -0600 To: users@tomcat.apache.org From: David Johle Subject: Re: Issues Logging wtith log4j at common and webapp levels Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Antivirus: AVG for E-mail 2013.0.2793 [2634/5934] X-Virus-Scanned: clamav-milter 0.97.6 at pig.industrialinfo.com X-Virus-Status: Clean X-Virus-Checked: Checked by ClamAV on apache.org 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