I had a couple questions regarding the following code which is included in a
weblogic sample application:


/**
 * <p>Controls Log4j logging level.  Implemented as a servlet so
 * that logging levels can be adjusted by redeploying the webapp.
 * Log file is determined by "log4j.config" set as a system
 * property in the server startup file.</p>
 *
 * @author Copyright (c) 2003 by BEA Systems. All Rights Reserved.
 */
public class Log4jInit extends HttpServlet {

  public void init() {

    int debug = 0;
    String value;
    String logFile;

    logFile = System.getProperty("log4j.config");
    value = getServletConfig().getInitParameter("debug");

    try {
            debug = Integer.parseInt(value);
    } catch (Throwable t) {
        debug = 0;
    }

    if (debug >= 1) {
      SimpleDateFormat formatter = new SimpleDateFormat("MMM d, yyyy H:mm:ss
a z");
      Date today = new Date();
      String output = "<"+formatter.format(today)+"> <Debug> <MedRec>";
      System.out.println(output+" Patient app log4j prop file: "+logFile);
    }

    // if the log4j-init-file is not set, then no point in trying
    if(logFile != null) {
      if (logFile.toString().toLowerCase().endsWith(".xml")) {
          DOMConfigurator.configure(logFile);
      } else {
        PropertyConfigurator.configure(logFile);
      }
    }
  }
}


1.      Does log4j need to be explicitly initialized this way?  If the
log4j.properties or log4j.xml file is in the classpath, won't log4j
initialize itself?
2.      This servlet gets a "debug" init parameter but never does anything
with it.  How would you switch logging levels with this information.  Can
you switch levels at runtime?

Thanks,

Joshua





This communication, including attachments, is for the exclusive use of 
addressee and may contain proprietary, confidential or privileged 
information. If you are not the intended recipient, any use, copying, 
disclosure, dissemination or distribution is strictly prohibited. If 
you are not the intended recipient, please notify the sender 
immediately by return email and delete this communication and destroy all copies.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to