Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Log4j log file not being created

800409Nov 30 2007 — edited Nov 30 2007
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 28 2007
Added on Nov 30 2007
3 comments
6,866 views