logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Moorer <tcm...@yahoo.com>
Subject Re: Default Initialization Servlet: Determine Hostname?
Date Mon, 11 May 2009 17:39:52 GMT
Brilliant!  I knew it would be something pretty straightforward...

I case anyone else is interested here's what I came up with:



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) {
        } catch (UnknownHostException e) {

email: tcm527@yahoo.com

From: Douglas E Wegscheid <Douglas_E_Wegscheid@whirlpool.com>
To: Log4J Users List <log4j-user@logging.apache.org>
Cc: log4j-user@logging.apache.org
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

Douglas E Wegscheid
Lead Technical Analyst, Whirlpool Corporation

"A wrong note played hesitatingly is a wrong note. A wrong note played 
with conviction is interpretation."

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