1 package Log::Message::Handlers;
\r
8 Log::Message::Handlers - Message handlers for Log::Message
\r
12 # Implicitly used by Log::Message to serve as handlers for
\r
13 # Log::Message::Item objects
\r
15 # Create your own file with a package called
\r
16 # Log::Message::Handlers to add to the existing ones, or to even
\r
26 Log::Message::Handlers provides handlers for Log::Message::Item objects.
\r
27 The handler corresponding to the level (see Log::Message::Item manpage
\r
28 for an explanation about levels) will be called automatically upon
\r
31 Handlers may also explicitly be called on an Log::Message::Item object
\r
32 if one so desires (see the Log::Message manpage on how to retrieve the
\r
35 =head1 Default Handlers
\r
39 Will simply log the error on the stack, and do nothing special
\r
47 Will carp (see the Carp manpage) with the error, and add the timestamp
\r
48 of when it occurred.
\r
54 warn join " ", $self->message, $self->shortmess, 'at', $self->when, "\n";
\r
59 Will croak (see the Carp manpage) with the error, and add the
\r
60 timestamp of when it occurred.
\r
66 die join " ", $self->message, $self->shortmess, 'at', $self->when, "\n";
\r
71 Will cluck (see the Carp manpage) with the error, and add the
\r
72 timestamp of when it occurred.
\r
78 warn join " ", $self->message, $self->longmess, 'at', $self->when, "\n";
\r
83 Will confess (see the Carp manpage) with the error, and add the
\r
84 timestamp of when it occurred
\r
90 die join " ", $self->message, $self->longmess, 'at', $self->when, "\n";
\r
95 Will simply die with the error message of the item
\r
99 sub die { die shift->message; }
\r
104 Will simply warn with the error message of the item
\r
108 sub warn { warn shift->message; }
\r
113 Will provide a traceback of this error item back to the first one that
\r
114 occurrent, clucking with every item as it comes across it.
\r
121 for my $item( $self->parent->retrieve( chrono => 0 ) ) {
\r
126 =head1 Custom Handlers
\r
128 If you wish to provide your own handlers, you can simply do the
\r
135 Create a file that holds a package by the name of
\r
136 C<Log::Message::Handlers>
\r
140 Create subroutines with the same name as the levels you wish to
\r
141 handle in the Log::Message module (see the Log::Message manpage for
\r
142 explanation on levels)
\r
146 Require that file in your program, or add it in your configuration
\r
147 (see the Log::Message::Config manpage for explanation on how to use a
\r
152 And that is it, the handler will now be available to handle messages
\r
155 The arguments a handler may receive are those specified by the
\r
156 C<extra> key, when storing the message.
\r
157 See the Log::Message manpage for details on the arguments.
\r
161 L<Log::Message>, L<Log::Message::Item>, L<Log::Message::Config>
\r
166 Jos Boumans E<lt>kane@cpan.orgE<gt>.
\r
168 =head1 Acknowledgements
\r
170 Thanks to Ann Barcomb for her suggestions.
\r
175 copyright (c) 2002 Jos Boumans E<lt>kane@cpan.orgE<gt>.
\r
176 All rights reserved.
\r
178 This library is free software;
\r
179 you may redistribute and/or modify it under the same
\r
180 terms as Perl itself.
\r
187 # c-indentation-style: bsd
\r
188 # c-basic-offset: 4
\r
189 # indent-tabs-mode: nil
\r
191 # vim: expandtab shiftwidth=4:
\r