On Sat, 05 Feb 2005 00:32:52 +0100, Rhesa Rozendaal <suppressed> wrote:
> I have one question (quite likely off topic), and that is: how do you
> turn off all logging except for errors? I assume you simply remove the
> loggers for a specific level?
> I read something in the Log4perl docs that said you could make certain
> logging calls no-ops, but didn't see anything like that in the
> LogDispatch docs. It sounds like a very efficient method (especially the
> tip to wrap the arguments to the log call in an anonymous sub, which
> could potentially save time), and I wonder if this is possible with
> LogDispatch as well.
There is a method in Log::Dispatch called 'would_log' which will
return true or false depending on if the given log-level would log or
not.
I generally don't worry about this sort of thing unless I am adding in
a tonne of debug lines that generate a lot of expensive data calls.
You are more likely to have bottlenecks in other parts of your code.
# should be very fast even with debugging off
$log->debug('This is a debug line');
# just as fast as above with debugging off, but probably slower otherwise
$log->debug('This is a debug line') if $log->would_log('debug');
# However, if you are doing expensive debug calls this will be slow since
# The data is generated, and then thrown away if we are not doing debug
# logging
$log->debug(generate_a_tonne_of_data());
# This will be much faster if debugging is turned off since the call to
# generate_a_tonne_of_data() doesn't happen
$log->debug(generate_a_tonne_of_data()) if $log->would_log('debug');
So I would only worry about doing the 'would_log' check if the data
being generated is large, or slow to generate.
If you are really concerned about performance, and want the log lines
to turn into no-ops, then you can always override the 'debug'
subroutine and have it return false in production ( sub debug () { 0 }
). That function will get optimized out at compile time, and all your
debug lines will not even be compiled into your perl runtime.
Cheers,
--
Cees Hek
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.