tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jerry Malcolm <2ndgenfi...@gmail.com>
Subject Re: Logging - including host name in log file?
Date Sat, 03 Dec 2011 02:45:37 GMT
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
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message