1. Printing the line number where the log_error was called without including it in the argument
The four Carp routines and the two Carp::Heavy routines provide this info (using caller).
use Carp (); sub log_error { goto(&Carp::carp) if pop(@_) >= THRESHOLD; }
I think Log::Log4perl also prints the file name and the line number. The above and Log::Log4perl don't meet your second requirement, however.
2. I'd like anything < THRESHOLD for the current run to be removed at compile time if possible to avoid a performance hit...not sure if can really do that...or if it makes a difference.
That's not possible if the level is passed as an argument. Your syntax would have to be
sub DEBUG () { 0 } sub FATAL () { 4 } sub THRESHOLD () { 0 } log_error($msg) if FATAL >= THRESHOLD;
Well, either that or use a source filter.
Maybe you could compile out debug messages, but leave the other ones in?
use Carp (); sub WARN () { 1 } sub ERROR () { 2 } sub DEBUG () { 0 } # True of false. sub THRESHOLD () { ERROR } # Or use $THRESHOLD. No real diff. sub log_error { my $level = (@_==2 ? pop(@_) : THRESHOLD); return if $level < THRESHOLD; goto &Carp::carp; } log_error($msg) if DEBUG; # Whole statement removed at compile time. log_error($msg, WARN); # Calls log_error, but not carp. log_error($msg, FATAL); # Calls log_error and carp.
In reply to Re: fast logging showing calling position..
by ikegami
in thread fast logging showing calling position..
by kosun
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |