logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam K" <ada...@gmail.com>
Subject Re: Log4J +struts
Date Thu, 14 Dec 2006 21:07:34 GMT
On 12/14/06, James Stauffer <stauffer.james@gmail.com> wrote:
>
> Two suggestions:
> 1. Use Logger logger = Logger.getLogger(getClass().getName());



Thanks for that piece of information, never even thought of using that.

2. Don't use code to configure but use an XML config file.  The
> configuration should only happen once so that is why you keep getting
> more log writers.


I have been trying to accomplish this one, but have been having a heck of a
time getting the log4j.properties file picked up.  I would be more than
happy to use a .xml version but I haven't had much luck finding a sample one
with writing to a file.  I am also a little confused as to how the logger is
supposed to find the config file.  Am I missing a simple faq or how-to that
describes this ?  Thanks again for the quick and concise answers.



On 12/14/06, Adam K <adamk1@gmail.com> wrote:
> > 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.
> >
> >
>
>
> --
> James Stauffer        http://www.geocities.com/stauffer_james/
> Are you good? Take the test at http://www.livingwaters.com/good/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

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