logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam K" <ada...@gmail.com>
Subject Log4J +struts
Date Thu, 14 Dec 2006 20:51:37 GMT
Hi all I am working with struts and was recently told about log4j.  I am
looking to implement this into an application, but have run into a couple of
issues.  I have so far managed to get the application to log to a file, but
not in the manner that I want.  Currently the application is logging by
placing the following code in a couple classes to test how log4j works.
(The capital letters and bold are replaced with what they should be )

This is declared at the top of each class:

static Logger logger = Logger.getLogger("NAMEOFCLASS.class");


The following is declared inside the execute method in each class:

        FileAppender myFileAppender = new FileAppender(new PatternLayout(),
"../log4jlog.log", true);
        myFileAppender.activateOptions();
        logger.addAppender(myFileAppender);
        logger.setLevel((Level) Level.DEBUG);

        logger.info("Entering NAMEOFCLASS");



This works, but as I said there are 2 issues.

1)  I don't want to be declaring the file location in each of the classes
2) Everytime I instantiate the class again I get another log writer.  I am
going to be trying to create a singleton version of the logger, but I am
somewhat confused as I thought each class used it's own logger.

Thanks in advance for any help you can provide.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message