1Log::Any::Adapter::DeveUlsoeprmeCnotn(t3r)ibuted Perl DoLcougm:e:nAtnayt:i:oAndapter::Development(3)
2
3
4
6 Log::Any::Adapter::Development -- Manual for developing new Log::Any
7 adapters
8
10 The adapter module:
11
12 package Log::Any::Adapter::YAL;
13 use strict;
14 use warnings;
15 use Log::Any::Adapter::Util qw(make_method);
16 use base qw(Log::Any::Adapter::Base);
17
18 # Optionally initialize object
19 #
20 sub init {
21 my ($self) = @_;
22
23 $self->{attr} = ...;
24 }
25
26 # Create logging methods: debug, info, etc.
27 #
28 foreach my $method ( Log::Any->logging_methods() ) {
29 make_method($method, sub { ... });
30 }
31
32 # Create detection methods: is_debug, is_info, etc.
33 #
34 foreach my $method ( Log::Any->detection_methods() ) {
35 make_method($method, sub { ... });
36 }
37
38 and the application:
39
40 Log::Any->set_adapter('YAL');
41
43 This document describes how to implement a new Log::Any adapter.
44
45 The easiest way to start is to look at the source of existing adapters,
46 such as Log::Any::Adapter::Log4perl and Log::Any::Adapter::Dispatch.
47
49 If you are going to publicly release your adapter, call it
50 'Log::Any::Adapter::something' so that users can use it with
51
52 Log::Any->set_adapter(I<something>);
53
54 If it's an internal driver, you can call it whatever you like and use
55 it like
56
57 Log::Any->set_adapter('+My::Log::Adapter');
58
60 All adapters must directly or indirectly inherit from
61 Log::Any::Adapter::Base.
62
64 Constructor
65 The constructor ("new") is provided by Log::Any::Adapter::Base. It
66 will:
67
68 · place any adapter arguments into a hash, along with the category
69
70 · bless the hash into your subclass
71
72 · call "init" which may be optionally provided by your subclass
73
74 At this point, overriding the default constructor is not supported.
75 Hopefully it will not be needed.
76
77 The constructor is called whenever a log object is requested. e.g. If
78 the application initializes Log::Any like so:
79
80 Log::Any->set_adapter('Log::YAL', yal_object => $yal, depth => 3);
81
82 and then a class requests a logger like so:
83
84 package Foo;
85 use Log::Any qw($log);
86
87 Then $log will be populated with the return value of:
88
89 Log::Any::Adapter::Yal->new(yal_object => $yal, depth => 3, category => 'Foo');
90
91 This is memoized, so if the same category should be requested again
92 (e.g. through a separate "get_logger" call, the same object will be
93 returned. Therefore, you should try to avoid anything non-
94 deterministic in your "init" function.
95
96 Required methods
97 The following methods have no default implementation, and MUST be
98 defined by your subclass:
99
100 debug ($msg)
101 info ($msg)
102 notice ($msg)
103 warning ($msg)
104 error ($msg)
105 critical ($msg)
106 alert ($msg)
107 emergency ($msg)
108 These methods log a message at the specified level.
109
110 To help generate these methods programmatically, you can get a list
111 of the method names with
112
113 Log::Any->logging_methods
114
115 is_debug ()
116 is_info ()
117 is_notice ()
118 is_warning ()
119 is_error ()
120 is_critical ()
121 is_alert ()
122 is_emergency ()
123 These methods return a boolean indicating whether the specified
124 level is active.
125
126 To help generate these methods programmatically, you can get a list
127 of the method names with
128
129 Log::Any->detection_methods
130
131 Optional methods
132 The following methods have no default implementation but MAY be
133 provided by your subclass:
134
135 init ()
136 This is called after the adapter object is created and blessed into
137 your class. It will be a hash containing the parameters that were
138 passed to new(). Perform any necessary validation or initialization
139 here.
140
141 Support methods
142 The following methods are useful for defining adapters:
143
144 delegate_method_to_slot ($slot, $method, $adapter_method)
145 Handle the specified $method by calling $adapter_method on the
146 object contained in $self->{$slot}.
147
148 See Log::Any::Adapter::Dispatch and Log::Any::Adapter::Log4perl for
149 examples of usage.
150
151 Log::Any->logging_methods
152 Returns a list of logging methods: debug, info, etc.
153
154 Log::Any->detection_methods
155 Returns a list of detection methods: is_debug, is_info, etc.
156
157 Log::Any->logging_and_detection_methods
158 Returns a combined list of logging and detection methods.
159
161 Jonathan Swartz
162
164 Log::Any
165
167 Copyright (C) 2009 Jonathan Swartz.
168
169 Log::Any is provided "as is" and without any express or implied
170 warranties, including, without limitation, the implied warranties of
171 merchantibility and fitness for a particular purpose.
172
173 This program is free software; you can redistribute it and/or modify it
174 under the same terms as Perl itself.
175
176
177
178perl v5.12.3 2009-10-27 Log::Any::Adapter::Development(3)