An alternative is to let the Appender handle figuring out what method
was used. There's the "%m" option for PatternLayoutAppender, for
example. It's much less clutter in your code, but has a runtime cost.
So for something that needs top performance, the "method Logger"
would be best. However for most environments & situations, the
runtime cost is worth the reduced setup and maintenance burden of
dealing with multiple Loggers in each class.
On Fri, 01 Oct 2004 12:12:42 +0200, David Tonhofer, m-plify S.A.
<[EMAIL PROTECTED]> wrote:
> -- On Friday, October 01, 2004 11:35 AM +0100 [EMAIL PROTECTED] wrote:
>
> > So you instantiate one logger for each method?
> > Isn't this very ressource-intensive, causing a bad performance?
>
> Yes, it certainly has a cost - however in this case it should not be
> too large - the code is used in long-running server and the cost is
> incurred at class load time only as all the Loggers are static. Penalty
> can be computed as 'initialization time per Logger' x 'numbers of declared
> Loggers' for the lifetime of the JVM. Should be in the 'a second or two
> range for lots of classes' - I haven't done any measurements though.
>
> The fact that I have one logger per method is a 'logging setup decision'.
> I you have Loggers:
>
> private final static Logger LOGGER_doStuff = Logger.getLogger(CLASS + ".doStuff");
>
> you can see in the logfile in what *method* something happened. If you have
> just one Logger:
>
> private final static Logger logger = Logger.getLogger(CLASS);
>
> you can see in the logfile in what *class* something happened. Which may or
> may not be sufficient.
>
> The fact of doing:
>
> public void doStuff() {
> Logger logger = LOGGER_doStuff;
> logger.info("Hello World");
> }
>
> inside the method is not going to hurt. This is just a reference copy from
> LOGGER_doStuff to logger at the start-of-method. Micro penalty.
>
> > Sorry I don't want to criticise you, just want to know the best way to work
> > with log4j
> >
> > Greets .. Herb
>
> Criticism is always good ;-)
>
> Best,
>
> -- David
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]