Log::Message::Handlers - Message handlers for Log::Message


Log-Message documentation Contained in the Log-Message distribution.

Index


Code Index:

NAME

Top

Log::Message::Handlers - Message handlers for Log::Message

SYNOPSIS

Top

    # Implicitly used by Log::Message to serve as handlers for
    # Log::Message::Item objects

    # Create your own file with a package called
    # Log::Message::Handlers to add to the existing ones, or to even
    # overwrite them

    $item->carp;

    $item->trace;




DESCRIPTION

Top

Log::Message::Handlers provides handlers for Log::Message::Item objects. The handler corresponding to the level (see Log::Message::Item manpage for an explanation about levels) will be called automatically upon storing the error.

Handlers may also explicitly be called on an Log::Message::Item object if one so desires (see the Log::Message manpage on how to retrieve the Item objects).

Default Handlers

Top

log

Will simply log the error on the stack, and do nothing special

carp

Will carp (see the Carp manpage) with the error, and add the timestamp of when it occurred.

croak

Will croak (see the Carp manpage) with the error, and add the timestamp of when it occurred.

cluck

Will cluck (see the Carp manpage) with the error, and add the timestamp of when it occurred.

confess

Will confess (see the Carp manpage) with the error, and add the timestamp of when it occurred

die

Will simply die with the error message of the item

warn

Will simply warn with the error message of the item

trace

Will provide a traceback of this error item back to the first one that occurred, clucking with every item as it comes across it.

Custom Handlers

Top

If you wish to provide your own handlers, you can simply do the following:

And that is it, the handler will now be available to handle messages for you.

The arguments a handler may receive are those specified by the extra key, when storing the message. See the Log::Message manpage for details on the arguments.

SEE ALSO

Top

Log::Message, Log::Message::Item, Log::Message::Config

AUTHOR

Top

This module by Jos Boumans <kane@cpan.org>.

Acknowledgements

Top

Thanks to Ann Barcomb for her suggestions.

COPYRIGHT

Top


Log-Message documentation Contained in the Log-Message distribution.
package Log::Message::Handlers;
use strict;
use vars qw[$VERSION];

$VERSION = '0.04';

sub log { 1 }

sub carp {
    my $self = shift;
    warn join " ", $self->message, $self->shortmess, 'at', $self->when, "\n";
}

sub croak {
    my $self = shift;
    die join " ", $self->message, $self->shortmess, 'at', $self->when, "\n";
}

sub cluck {
    my $self = shift;
    warn join " ", $self->message, $self->longmess, 'at', $self->when, "\n";
}

sub confess {
    my $self = shift;
    die join " ", $self->message, $self->longmess, 'at', $self->when, "\n";
}

sub die  { die  shift->message; }


sub warn { warn shift->message; }


sub trace {
    my $self = shift;

    for my $item( $self->parent->retrieve( chrono => 0 ) ) {
        $item->cluck;
    }
}

1;

# Local variables:
# c-indentation-style: bsd
# c-basic-offset: 4
# indent-tabs-mode: nil
# End:
# vim: expandtab shiftwidth=4: