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 BE9FA7602 for ; Sat, 3 Dec 2011 02:46:10 +0000 (UTC) Received: (qmail 93150 invoked by uid 500); 3 Dec 2011 02:46:07 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 93013 invoked by uid 500); 3 Dec 2011 02:46:07 -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 93004 invoked by uid 99); 3 Dec 2011 02:46:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 03 Dec 2011 02:46:05 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of 2ndgenfilms@gmail.com designates 209.85.213.45 as permitted sender) Received: from [209.85.213.45] (HELO mail-yw0-f45.google.com) (209.85.213.45) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 03 Dec 2011 02:45:59 +0000 Received: by ywe9 with SMTP id 9so4093626ywe.18 for ; Fri, 02 Dec 2011 18:45:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=/B2g0BahzRzi1MuCCpYxZ5TZZvFxyYl8W/Wu7N+cfvg=; b=E5QJDYp/LOUq2gQuy5kQvlPp8BLBtO69oazu3pgVBGYXHgJGM3CHGPvqukx5E7tFFn CKtt/0htdPEm2MTt7Oneg+6XeVmAx1M8FkDNAHqkrJYJQ8G/Gag/CF2JT5SbhB7UKC2u BXq9Ig8KN5sImrZb7eSa0rBQHk8A8HjC2Ae1I= MIME-Version: 1.0 Received: by 10.236.123.107 with SMTP id u71mr756309yhh.130.1322880337883; Fri, 02 Dec 2011 18:45:37 -0800 (PST) Received: by 10.236.70.100 with HTTP; Fri, 2 Dec 2011 18:45:37 -0800 (PST) In-Reply-To: <4ED92F54.7020003@christopherschultz.net> References: <4ED83CDE.4040702@christopherschultz.net> <4ED92F54.7020003@christopherschultz.net> Date: Fri, 2 Dec 2011 20:45:37 -0600 Message-ID: Subject: Re: Logging - including host name in log file? From: Jerry Malcolm <2ndgenfilms@gmail.com> To: Tomcat Users List Content-Type: multipart/alternative; boundary=20cf301b65799eb34504b327148f X-Virus-Checked: Checked by ClamAV on apache.org --20cf301b65799eb34504b327148f Content-Type: text/plain; charset=ISO-8859-1 Thanks for all of your help. I decided it was going to be difficult to maintain/update the static properties file for all of the different host/apps. So I decided to pursue dynamic configuration at runtime (with success). Each time I need a logger, I simply instantiate a tomcat FileHandler and build the file name from the catalina base, the server name, and the context. This seems fairly straightforward, and again, it is working. But if there is something in this implementation that's going to bite me, please let me know now. I've got it all working now, except for one specific situation... I have some servlets that run at startup. I have googled and looked everywhere i can think of.... but I cannot figure out how to find the host name while inside a servlet init method. In other situations, I pull the server name from the request object. But when a servlet is running at startup, there is no request object. I have a ServletConfig and can get the ServletContext. But I can't find the host name in those. A context runs in a host. It seems to me that the context would report the host it is in, independent of whether a request is in progress of not. This is not a show-stopper on the overall logging transition for me. But I would sure love to find a way to know the host that this context is running under without requiring a request object. Am I missing something obvious? Thanks again. Jerry On Fri, Dec 2, 2011 at 2:04 PM, Christopher Schultz < chris@christopherschultz.net> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Jerry, > > On 12/2/11 12:46 PM, Jerry Malcolm wrote: > > Ok, I'm digging into this. Slowly but surely.... Just to > > confirm... > > > > So if I have, say 2 hosts, each with 3 web apps, and I want a > > different log file for each web app on each host, I need to define > > 6 of the following: > > > > 10host1webapp1.org.apache.juli.FileHandler.level = FINE > > 10host1webapp1.org.apache.juli.FileHandler.directory = > > ${catalina.base}/logs > > 10host1webapp1.org.apache.juli.FileHandler.prefix = Host1App1. > > Yes, although the format of the property base doesn't need to be that > complex. You could do this: > > Host1App1.level=FINE > Host1App1.directory=... > Host1App1.prefix=Host1App1. > > Tomcat has those odd property names so they will be unlikely to > conflict with anything you might want to define yourself. > > The magic happens here, when you actually configure Tomcat's logger(s): > > > > > And then define 6 of the following: > > > > > org.apache.catalina.core.ContainerBase.[Catalina].[host1].[/webapp1].level > > > > > = INFO > > > org.apache.catalina.core.ContainerBase.[Catalina].[host1].[/webapp1].handlers > > > > > = 10host1webapp1.org.apache.juli.FileHandler > > You could instead do: > > > org.apache.catalina.core.ContainerBase.[Catalina].[host1].[/webapp1].handlers=Host1App1 > > > and I put all of this in /conf/logging.properties > > Yes: this will tell Tomcat that, when your webapp uses > ServletContext.log(...) that the output should go to those loggers > listed in the "handlers" property for that particular webapp. > > > All of this is required in order to get separate log files per > > webapp per host, right? > > - From ServletContext.log(..), yes. > > Again, if your webapp is logging in some other way, then Tomcat's > configuration does not apply at all. It's fairly common for webapps to > use their own logging mechanism rather than logging to the servlet > container, so I wouldn't be surprised if you have more work to do. > > - -chris > -----BEGIN PGP SIGNATURE----- > Version: GnuPG/MacGPG2 v2.0.17 (Darwin) > Comment: GPGTools - http://gpgtools.org > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iEYEARECAAYFAk7ZL1QACgkQ9CaO5/Lv0PCOtACgrrhT1KS0QjOOF+Swh+jGqfZS > bGYAn3sg6wcPwg9HtLrXDcHkMFxXIz3W > =LSuQ > -----END PGP SIGNATURE----- > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org > For additional commands, e-mail: users-help@tomcat.apache.org > > --20cf301b65799eb34504b327148f--