This discussion is archived
3 Replies Latest reply: Nov 30, 2007 8:59 AM by 800409 RSS

Log4j log file not being created

800409 Newbie
Currently Being Moderated
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.
log4j.rootLogger=INFO,ROOT
log4j.appender.ROOT=org.apache.log4j.RollingFileAppender
log4j.appender.ROOT.File=c:\myapplication.log
log4j.appender.ROOT.MaxFileSize=1000KB
#Keep 5 old files around.
log4j.appender.ROOT.MaxBackupIndex=5
log4j.appender.ROOT.layout=org.apache.log4j.PatternLayout
#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
log4j.logger.com.webage.ejbs=INFO        



private static final Logger logger = Logger.getLogger(LoginAction.class);

    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        
        initializeLogger();



private void initializeLogger() {
        org.apache.log4j.BasicConfigurator.configure();
//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(
                    "LOG4J_XML");
            if (!(log4jUrl == null || log4jUrl.equals("")))
                DOMConfigurator.configure(servlet.getServletContext()
                        .getResource(log4jUrl));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (FactoryConfigurationError e) {
            e.printStackTrace();
        }*/
    }    
Edited by: gmachamer on Nov 30, 2007 6:37 AM
  • 1. Re: Log4j log file not being created
    800409 Newbie
    Currently Being Moderated
    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
    800409 Newbie
    Currently Being Moderated
    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"/> 
                  </layout> 
           </appender> 
    
           <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"/>
                      </layout>           
              </appender>
    
           <root> 
                  <priority value ="error" /> 
                  <appender-ref ref="rollingFileAppender" />
                  <appender-ref ref="console" /> 
               
           </root>  
    </log4j:configuration>
  • 3. Re: Log4j log file not being created
    800409 Newbie
    Currently Being Moderated
    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?