Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Assertions and Logging

by nop (Hermit)
on Dec 09, 2002 at 16:11 UTC ( #218568=perlquestion: print w/ replies, xml ) Need Help??
nop has asked for the wisdom of the Perl Monks concerning the following question:

Hi. I'm using log4perl, and I'm using Carp::assert with $Carp::Verbose = 1.
My questions are:
How can I integrate the assertions with the logging?
Is it possible to have assertions that fail with warnings, rather than fatally?
Can I get my failed assertions into my log4perl log, rather than to stderr?
Thanks -- nop

Comment on Assertions and Logging
Download Code
Re: Assertions and Logging
by demerphq (Chancellor) on Dec 09, 2002 at 17:59 UTC
    As the new maintainer (as of Friday :-) of that module i'm happy to consider this idea. However you'll have to give some more info about what you have in mind. Also what is "log4perl"?

    --- demerphq
    my friends call me, usually because I'm late....

Re: Assertions and Logging
by tall_man (Parson) on Dec 09, 2002 at 22:09 UTC
    The following is the code for Carp::Assert::assert.
    sub assert ($;$) { unless($_[0]) { require Carp; Carp::confess( _fail_msg($_[1]) ); } return undef; }

    If you don't use Carp::confess elsewhere, you could override it to call Log::Log4perl.

Re: Assertions and Logging
by BrowserUk (Pope) on Dec 09, 2002 at 22:23 UTC

    Having taken a look at Log:Log4perl, it seems to me that using it and Carp::Assert in combination is entirely the wrong thing to do. If you want to log warnings use the WARN category of Log4perl messages.

    The whole point of Carp::Assert (from my reading) is that it is designed for testing fail conditions from which there is no recovery and that when it is switched off, it has minimum impact on the script that uses it.

    It's design criteria, and the idea of permenently enabling it to log Warning conditions seem to be fundementally in conflict?


    Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
    Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
    Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
    Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://218568]
Approved by gjb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2014-08-29 18:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (286 votes), past polls