1Log::Any::Adapter(3) User Contributed Perl Documentation Log::Any::Adapter(3)
2
3
4
6 Log::Any::Adapter -- Tell Log::Any where to send its logs
7
9 use Log::Any::Adapter;
10
11 # Use Log::Log4perl for all categories
12 #
13 Log::Log4perl::init('/etc/log4perl.conf');
14 Log::Any::Adapter->set('Log4perl');
15
16 # Use Log::Dispatch for Foo::Baz
17 #
18 use Log::Dispatch;
19 my $log = Log::Dispatch->new(outputs => [[ ... ]]);
20 Log::Any::Adapter->set( { category => 'Foo::Baz' },
21 'Dispatch', dispatcher => $log );
22
23 # Use Log::Dispatch::Config for Foo::Baz and its subcategories
24 #
25 use Log::Dispatch::Config;
26 Log::Dispatch::Config->configure('/path/to/log.conf');
27 Log::Any::Adapter->set(
28 { category => qr/^Foo::Baz/ },
29 'Dispatch', dispatcher => Log::Dispatch::Config->instance() );
30
31 # Use your own adapter for all categories
32 #
33 Log::Any::Adapter->set('+My::Log::Any::Adapter', ...);
34
36 The "Log-Any-Adapter" distribution implements Log::Any class methods to
37 specify where logs should be sent. It is a separate distribution so as
38 to keep "Log::Any" itself as simple and unchanging as possible.
39
40 You do not have to use anything in this distribution explicitly. It
41 will be auto-loaded when you call one of the methods below.
42
44 In order to use a logging mechanism with "Log::Any", there needs to be
45 an adapter class for it. Typically this is named
46 Log::Any::Adapter::something.
47
48 The following adapters are available on CPAN as of this writing:
49
50 · Log::Any::Adapter::Log4perl - work with log4perl
51
52 · Log::Any::Adapter::Dispatch - work with Log::Dispatch or
53 Log::Dispatch::Config
54
55 You may also find other adapters on CPAN by searching for
56 "Log::Any::Adapter", or create your own adapter. See
57 Log::Any::Adapter::Development for more information on the latter.
58
60 Log::Any::Adapter->set ([options, ]adapter_name, adapter_params...)
61 This method sets the adapter to use for all log categories, or for
62 a particular set of categories.
63
64 adapter_name is the name of an adapter. It is automatically
65 prepended with "Log::Any::Adapter::". If instead you want to pass
66 the full name of an adapter, prefix it with a "+". e.g.
67
68 # Use My::Adapter class
69 Log::Any::Adapter->set('+My::Adapter', arg => $value);
70
71 adapter_params are passed along to the adapter constructor. See the
72 documentation for the individual adapter classes for more
73 information.
74
75 An optional hash of options may be passed as the first argument.
76 Options are:
77
78 category
79 A string containing a category name, or a regex (created with
80 qr//) matching multiple categories. If not specified, all
81 categories will be affected.
82
83 lexically
84 A reference to a lexical variable. When the variable goes out
85 of scope, the adapter setting will be removed. e.g.
86
87 {
88 Log::Any::Adapter->set({lexically => \my $lex}, ...);
89
90 # in effect here
91 ...
92 }
93 # no longer in effect here
94
95 "set" returns an entry object, which can be passed to "remove".
96
97 Log::Any::Adapter->remove (entry)
98 Remove an entry previously returned by "set".
99
101 "Log::Any" maintains a stack of entries created via "set".
102
103 When you get a logger for a particular category, "Log::Any" will work
104 its way down the stack and use the first matching entry.
105
106 Whenever the stack changes, any "Log::Any" loggers that have previously
107 been created will automatically adjust to the new stack. For example:
108
109 my $log = Log::Any->get_logger();
110 $log->error("aiggh!"); # this goes nowhere
111 ...
112 {
113 Log::Any::Adapter->set({ local => \my $lex }, 'Log4perl');
114 $log->error("aiggh!"); # this goes to log4perl
115 ...
116 }
117 $log->error("aiggh!"); # this goes nowhere again
118
120 Log::Any
121
123 Jonathan Swartz
124
126 Copyright (C) 2009 Jonathan Swartz.
127
128 Log::Any is provided "as is" and without any express or implied
129 warranties, including, without limitation, the implied warranties of
130 merchantibility and fitness for a particular purpose.
131
132 This program is free software; you canredistribute it and/or modify it
133 under the same terms as Perl itself.
134
135
136
137perl v5.12.3 2009-10-28 Log::Any::Adapter(3)