tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Cheshire <>
Subject environment variables for hostname and context name
Date Sat, 19 Sep 2009 00:18:08 GMT
I'm reconfiguring the logging for my tomcat installation (6.0.20) to
use logback (instead of log4j) for the server logging so I can split
out error messages on a per host basis. I see that "catalina.home" is
exposed as an environment var and usable in the logging configuration
file - what about the hostname and context name/path?

I would like to set up a config file such that I don't have to edit it
every time I add a new sandbox for a developer (host). I want the
errors split out per host instead of one big file, because it makes it
possible to tell which sandbox had a problem with a JSP page for

I have it working if I hardcode a new appender per host going to a
separate file - something like :

  <root level="INFO">
    <appender-ref ref="tomcat" />

  <logger name="org.apache.catalina.core.ContainerBase.[Catalina].[]"
    <appender-ref ref="tomcat_www" />

and then two appenders, one for base logging from the tomcat
container, and then one for the host "".

  <appender name="tomcat_www"
    <RollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

    <layout class="ch.qos.logback.classic.PatternLayout">
      <Pattern>%-25(%date{HH:mm:ss.SSS} [%thread])

Now when I log an error I see something like :

17:04:01.890 [http-8080-1] ERROR
Servlet.service() for servlet default threw exception
org.apache.jasper.JasperException: /WEB-INF/jsp/login.jsp(17,2)
Unterminated &lt;core:if tag
        at org.apache.jasper.compiler.DefaultErrorHandler.jspError(

[blah blah blah]

"" is the host where the web app is deployed. "foo" is the
context path under which the app is deployed. So if it was able to log
this information, it must be accessible somewhere, right? If I can get
access to the hostname and context name I can specify a dynamic file
name using these variables, and then only have one appender defined no
matter how many new hosts I deploy.


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

View raw message