Brilliant! I knew it would be something pretty straightforward...
I case anyone else is interested here's what I came up with:
web.xml
<servlet>
<description></description>
<display-name>Log4jInit</display-name>
<servlet-name>Log4jInit</servlet-name>
<servlet-class>core.app.controllers.Log4jInit</servlet-class>
<init-param>
<param-name>log4j-dev</param-name>
<param-value>WEB-INF/classes/log4j-dev.properties</param-value>
</init-param>
<init-param>
<param-name>log4j-prd</param-name>
<param-value>WEB-INF/classes/log4j-prd.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Log4jInit</servlet-name>
<url-pattern>/Log4jInit</url-pattern>
</servlet-mapping>
Log4jInit servlet
public void init(ServletConfig config) throws ServletException {
try {
InetAddress localhost = InetAddress.getLocalHost();
String hostname = localhost.getHostName();
String parmName = "log4j-dev";
if (hostname.contains("...dev") || hostname.contains("...prd")) {
parmName = "log4j-prd";
}
String propFile =
config.getServletContext().getRealPath("/"+config.getInitParameter(parmName));
//System.out.println(this.getClass()+": hostname='"+hostname+"'");
//System.out.println(this.getClass()+": propFile='"+propFile+"'");
if(propFile!= null) {
PropertyConfigurator.configure(propFile);
}
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
email: [email protected]
________________________________
From: Douglas E Wegscheid <[email protected]>
To: Log4J Users List <[email protected]>
Cc: [email protected]
Sent: Monday, May 11, 2009 12:59:14 PM
Subject: Re: Default Initialization Servlet: Determine Hostname?
this should be pretty straightforward: you can determine hostname with
InetAddress.getLocalHost(). after that, it's just code.
you probably won't get an address of "localhost" back, though. localhost
usually (always?) maps to 127.0.0.1...
Douglas E Wegscheid
Lead Technical Analyst, Whirlpool Corporation
(269)-923-5278
"A wrong note played hesitatingly is a wrong note. A wrong note played
with conviction is interpretation."