Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (2)
    As of 2018-11-15 20:38 GMT
    Find Nodes?
      Voting Booth?
      My code is most likely broken because:

      Results (192 votes). Check out past polls.

      • (Sep 10, 2018 at 22:53 UTC) Welcome new users!