1Log::Dispatch::Output(3U)ser Contributed Perl DocumentatiLoong::Dispatch::Output(3)
2
3
4
6 Log::Dispatch::Output - Base class for all Log::Dispatch::* objects
7
9 version 2.70
10
12 package Log::Dispatch::MySubclass;
13
14 use Log::Dispatch::Output;
15 use base qw( Log::Dispatch::Output );
16
17 sub new {
18 my $proto = shift;
19 my $class = ref $proto || $proto;
20
21 my %p = @_;
22
23 my $self = bless {}, $class;
24
25 $self->_basic_init(%p);
26
27 # Do more if you like
28
29 return $self;
30 }
31
32 sub log_message {
33 my $self = shift;
34 my %p = @_;
35
36 # Do something with message in $p{message}
37 }
38
39 1;
40
42 This module is the base class from which all Log::Dispatch::* objects
43 should be derived.
44
46 The constructor, "new", must be overridden in a subclass. See Output
47 Classes for a description of the common parameters accepted by this
48 constructor.
49
51 This class provides the following methods:
52
53 $output->_basic_init(%p)
54 This should be called from a subclass's constructor. Make sure to pass
55 the arguments in @_ to it. It sets the object's name and minimum level
56 from the passed parameters It also sets up two other attributes which
57 are used by other Log::Dispatch::Output methods, level_names and
58 level_numbers. Subclasses will perform parameter validation in this
59 method, and must also call the superclass's method.
60
61 $output->name
62 Returns the object's name.
63
64 $output->min_level
65 Returns the object's minimum log level.
66
67 $output->max_level
68 Returns the object's maximum log level.
69
70 $output->accepted_levels
71 Returns a list of the object's accepted levels (by name) from minimum
72 to maximum.
73
74 $output->log( level => $, message => $ )
75 Sends a message if the level is greater than or equal to the object's
76 minimum level. This method applies any message formatting callbacks
77 that the object may have.
78
79 $output->_should_log ($)
80 This method is called from the "log()" method with the log level of the
81 message to be logged as an argument. It returns a boolean value
82 indicating whether or not the message should be logged by this
83 particular object. The "log()" method will not process the message if
84 the return value is false.
85
86 $output->_level_as_number ($)
87 This method will take a log level as a string (or a number) and return
88 the number of that log level. If not given an argument, it returns the
89 calling object's log level instead. If it cannot determine the level
90 then it will croak.
91
92 $output->add_callback( $code )
93 Adds a callback (like those given during construction). It is added to
94 the end of the list of callbacks.
95
96 $dispatch->remove_callback( $code )
97 Remove the given callback from the list of callbacks.
98
100 This class should be used as the base class for all logging objects you
101 create that you would like to work under the Log::Dispatch
102 architecture. Subclassing is fairly trivial. For most subclasses, if
103 you simply copy the code in the SYNOPSIS and then put some
104 functionality into the "log_message" method then you should be all set.
105 Please make sure to use the "_basic_init" method as described above.
106
107 The actual logging implementation should be done in a "log_message"
108 method that you write. Do not override "log"!.
109
111 Bugs may be submitted at
112 <https://github.com/houseabsolute/Log-Dispatch/issues>.
113
114 I am also usually active on IRC as 'autarch' on "irc://irc.perl.org".
115
117 The source code repository for Log-Dispatch can be found at
118 <https://github.com/houseabsolute/Log-Dispatch>.
119
121 Dave Rolsky <autarch@urth.org>
122
124 This software is Copyright (c) 2020 by Dave Rolsky.
125
126 This is free software, licensed under:
127
128 The Artistic License 2.0 (GPL Compatible)
129
130 The full text of the license can be found in the LICENSE file included
131 with this distribution.
132
133
134
135perl v5.34.0 2021-07-22 Log::Dispatch::Output(3)