3 Replies Latest reply on Nov 30, 2007 4:59 PM by 800409

    Log4j log file not being created

      Using websphere for a web app. At first I was getting the error log4j:WARN No appenders could be found for logger....

      So I created the property file and I assume correctly referenced it. The error went away and my logging messages are showing up in the websphere console, but the .log file specified in my log4j.properties file is not being written to... it is only writing to my systemOut.log.

      If I remove the ROOT.File line it still does not create the file (I've done a search on the IBM directory
      #Default log level to ERROR. Other levels are INFO and DEBUG.
      #Keep 5 old files around.
      #Format almost same as WebSphere's common log format.
      log4j.appender.ROOT.layout.ConversionPattern=[%d] %t %c %-5p - %m%n
      #Optionally override log level of individual packages or classes
      private static final Logger logger = Logger.getLogger(LoginAction.class);
          public ActionForward execute(ActionMapping mapping, ActionForm form,
                  HttpServletRequest request, HttpServletResponse response)
                  throws IOException, ServletException {
      private void initializeLogger() {
      //trying the above just to get it to work.. because by default this 
      //should look in WEB-INF/classes/log4j.properties... I thought
              /*try {
                  String log4jUrl = servlet.getServletContext().getInitParameter(
                  if (!(log4jUrl == null || log4jUrl.equals("")))
              } catch (MalformedURLException e) {
              } catch (FactoryConfigurationError e) {
      Edited by: gmachamer on Nov 30, 2007 6:37 AM
        • 1. Re: Log4j log file not being created
          ok Here is what I learned.

          When I go into debug mode (websphere not log4j) and view the logger object, no level is set, so it looks like the properties file is not being read correctly... also org.apache.log4j.helpers.Loader.getResource("log4j.properties"); is returning null, so I think that supports the fact that the log4j file is not being found?

          it is located in my JavaSource directory and gets deployed to my classes directory. Is there something I could be doing wrong when I initialize my logger that would cause it to look in the wrong place?
          • 2. Re: Log4j log file not being created
            ok changed to xml file and found a few things out.

            now when I debug though the logger that was created has an empty level... but if I look at the parent logger it is correctly pulling the root logger from my xml (if I change the priority attribute then it changes when debugging the code)
            <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
                 <!-- this appender would be the same as having a System.out -->
                 <appender name="console" class="org.apache.log4j.ConsoleAppender"> 
                      <param name="Target" value="System.out"/> 
                      <layout class="org.apache.log4j.PatternLayout"> 
                                 <param name="ConversionPattern" value="%-5p %c{1} - %m%n"/> 
                   <appender name="rollingFileAppender" class="org.apache.log4j.RollingFileAppender">
                      <!-- name and location of the file to log to -->
                         <param name="File" value="c:/appLog.log"/>
                      <!-- the maximum size the file will be before it rolls the file -->
                         <param name="MaxFileSize" value="1000kb"/>
                      <!-- the number of backups you want to maintain -->
                      <param name="MaxBackupIndex" value="5"/>
                           This is the layout of your messages, you can do alot with this.
                           See the java docs for the class PatternLayout for an explanation of 
                           the different values you can have.
                         <layout class="org.apache.log4j.PatternLayout">
                                  <param name="ConversionPattern" value="%t %-5p %c{2} - %m%n"/>
                          <priority value ="error" /> 
                          <appender-ref ref="rollingFileAppender" />
                          <appender-ref ref="console" /> 
            • 3. Re: Log4j log file not being created
              something is messed up.. if I add a <logger> that has an error in it then I will get an exception parsing it and it will start outputting. Then if remove the error it starts working fine... but if I save it and restart the server it stops working again?