tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: Logging - including host name in log file?
Date Fri, 02 Dec 2011 02:50:06 GMT
Hash: SHA1


On 12/1/11 9:21 PM, Jerry Malcolm wrote:
> I'm trying to get my hands around the whole tomcat logging system.
> I've read the docs, wikis, samples, etc.  But I still struggling a
> bit.  I've been just using System.out.println for years, and it's
> getting totally out of control.  So time to learn tomcat logging.

Yup. System.out is insanely inflexible.

> Basically, I host quite a few domains.  I'd like to separate the
> log files per host (and possibly further subdivide by webapps).  I
> can't find any way to specify the host as part of the logger file
> handler directory.  This may be something intuitively obvious.  But
> I haven't found it yet.

Which logging system are you using? Tomcat's default is to use JULI
which connects commons-logging up to the java.util.logging (or J-U-L
Interface, hence "JULI").

At any rate, the standard file should have examples
that make this work. For instance, I can see the following in mine:


All that mess configures a logger that captures the logs for the
"manager" <Context> that is deployed into the "localhost" <Host> under
the "Catalina" <Service>.

You can easily create one of these for each of your webapps (or even
just per host) in the same way: just use the proper Service, Host, and
context path (contexts don't have names, so you use the context path
instead -- the above for an example).

So, let's say that you have:

<Service name="Catalina">
  <Host name="">
    <Context path="/sweetwebapp" docBase="..." ... />

(But, of course, you don't have that because you shouldn't put
<Context>s in server.xml, but I have it here for the sake of brevity).

Anyhow, you can configure a logger for that context like this:


(plus the other configuration you'll need like which file to use, etc.)

> If it can't be configured statically to plug the host name into the
> log file name with a variable or something like ${catalina_home},
> alternatively is there a way to change the file name on the fly
> after getting an instance of the java.utils.logging.Logger class?

If you are using Tomcat's internal logging (which is done by calling
ServletContext.log(...)) then you should use lib/ as
described above.

If you are using java.util.logging directly in your own webapp, then
you are on your own :(

If you are using AccessLogValve, well then you just need to use "%v"
to get the name of the local server -- but that's for the actual log
data, not for the filename.

- -chris
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools -
Comment: Using GnuPG with Mozilla -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message