log4j in Struts

I am trying to use log4j in a Struts application that I am developing. I have a utility class in which I initialize my logger in a static block. I have something like this:

public class UtilClass {

private static String dateFormat = "dd-MMM-yyyy";

private static Logger logger = Logger.getLogger("MyLogger");

static {

RollingFileAppender appender = null;

try {

ResourceBundle bundle = ResourceBundle.getBundle(Constants.APPLICATION_RESOURCE);

PatternLayout pl = new PatternLayout("%d - %m%n");

appender = new RollingFileAppender(pl, bundle.getString("logFile"));

appender.setMaxBackupIndex(5);

appender.setMaxFileSize("10MB");

logger.addAppender(appender);

logger.setLevel((Level) Level.toLevel(bundle.getString(

"loggerLevel")));

} catch (Exception e) {

e.printStackTrace();

}

}

public static void addLog(String msg) {

logger.error(msg);

}

public static void addLogInfo(String msg) {

logger.info(msg);

}

public static void addLogDebug(String msg) {

logger.debug(msg);

}

...

}

Then, when I want to log an event in another class I simply use the static methods in UtilClass, like:

catch(Exception e) {

UtilClass.addLog( "Message: " + e.getMessage());

}

However, it doesn't seem to work. When I run the app, I get two warning messages:

1. log4j:WARN No appenders could be found for logger (org.apache.struts.util.PropertyMessageResources)

2. log4j:WARN Please initialize the log4j system properly.

This is my first attempt at log4j, so I am a little befuddled.

I am using an OC4J app server

Any suggestions would be much appreciated.

Thanks

Message was edited by:

dsh2va

[1829 byte] By [dsh2vaa] at [2007-11-27 6:10:45]
# 1
I am guessing you have read some sort of tutorial, so you might want to go back and read about the part that lists either a log4j.properties or a log4j.xml.
Aknibbsa at 2007-7-12 17:16:28 > top of Java-index,Java Essentials,Java Programming...