/usr/share/perl5/Log/Any/Adapter.pm is in liblog-any-perl 1.038-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | use 5.008001;
use strict;
use warnings;
package Log::Any::Adapter;
# ABSTRACT: Tell Log::Any where to send its logs
our $VERSION = '1.038';
use Log::Any;
sub import {
my $pkg = shift;
Log::Any->_manager->set(@_) if (@_);
}
sub set {
my $pkg = shift;
Log::Any->_manager->set(@_)
}
sub remove {
my $pkg = shift;
Log::Any->_manager->remove(@_)
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Log::Any::Adapter - Tell Log::Any where to send its logs
=head1 VERSION
version 1.038
=head1 SYNOPSIS
# Log to a file, or stdout, or stderr for all categories
#
use Log::Any::Adapter ('File', '/path/to/file.log');
use Log::Any::Adapter ('Stdout');
use Log::Any::Adapter ('Stderr');
# Use Log::Log4perl for all categories
#
Log::Log4perl::init('/etc/log4perl.conf');
Log::Any::Adapter->set('Log4perl');
# Use Log::Dispatch for Foo::Baz
#
use Log::Dispatch;
my $log = Log::Dispatch->new(outputs => [[ ... ]]);
Log::Any::Adapter->set( { category => 'Foo::Baz' },
'Dispatch', dispatcher => $log );
# Use Log::Dispatch::Config for Foo::Baz and its subcategories
#
use Log::Dispatch::Config;
Log::Dispatch::Config->configure('/path/to/log.conf');
Log::Any::Adapter->set(
{ category => qr/^Foo::Baz/ },
'Dispatch', dispatcher => Log::Dispatch::Config->instance() );
# Use your own adapter for all categories
#
Log::Any::Adapter->set('+My::Log::Any::Adapter', ...);
=head1 DESCRIPTION
Log::Any::Adapter connects log producers and log consumers. Its methods
instantiate a logging adapter (a subclass of L<Log::Any::Adapter::Base>)
and route log messages from one or more categories to it.
=head1 NAME
Log::Any::Adapter - Tell Log::Any where to send its logs
=head1 VERSION
version 1.038
=head1 ADAPTERS
In order to use a logging mechanism with C<Log::Any>, there needs to be an
adapter class for it. Typically this is named Log::Any::Adapter::I<something>.
=head2 Adapters in this distribution
Three basic adapters come with this distribution -- L<Log::Any::Adapter::File>,
L<Log::Any::Adapter::Stdout> and L<Log::Any::Adapter::Stderr>:
use Log::Any::Adapter ('File', '/path/to/file.log');
use Log::Any::Adapter ('Stdout');
use Log::Any::Adapter ('Stderr');
# or
use Log::Any::Adapter;
Log::Any::Adapter->set('File', '/path/to/file.log');
Log::Any::Adapter->set('Stdout');
Log::Any::Adapter->set('Stderr');
All of them simply output the message and newline to the specified destination;
a datestamp prefix is added in the C<File> case. For anything more complex
you'll want to use a more robust adapter from CPAN.
=head2 Adapters on CPAN
A sampling of adapters available on CPAN as of this writing:
=over
=item *
L<Log::Any::Adapter::Log4perl|Log::Any::Adapter::Log4perl>
=item *
L<Log::Any::Adapter::Dispatch|Log::Any::Adapter::Dispatch>
=item *
L<Log::Any::Adapter::FileHandle|Log::Any::Adapter::FileHandle>
=item *
L<Log::Any::Adapter::Syslog|Log::Any::Adapter::Syslog>
=back
You may find other adapters on CPAN by searching for "Log::Any::Adapter", or
create your own adapter. See
L<Log::Any::Adapter::Development|Log::Any::Adapter::Development> for more
information on the latter.
=head1 SETTING AND REMOVING ADAPTERS
=over
=item Log::Any::Adapter->set ([options, ]adapter_name, adapter_params...)
This method sets the adapter to use for all log categories, or for a particular
set of categories.
I<adapter_name> is the name of an adapter. It is automatically prepended with
"Log::Any::Adapter::". If instead you want to pass the full name of an adapter,
prefix it with a "+". e.g.
# Use My::Adapter class
Log::Any::Adapter->set('+My::Adapter', arg => $value);
I<adapter_params> are passed along to the adapter constructor. See the
documentation for the individual adapter classes for more information.
An optional hash of I<options> may be passed as the first argument. Options
are:
=over
=item category
A string containing a category name, or a regex (created with C<qr//>) matching
multiple categories. If not specified, all categories will be routed to the
adapter.
=item lexically
A reference to a lexical variable. When the variable goes out of scope, the
adapter setting will be removed. e.g.
{
Log::Any::Adapter->set({lexically => \my $lex}, ...);
# in effect here
...
}
# no longer in effect here
=back
C<set> returns an entry object, which can be passed to C<remove>. If you
call C<set> repeatedly without calling C<remove> you will leak memory. For
most programs that set an adapter once until the end of the program, this
shouldn't matter.
=item use Log::Any::Adapter (...)
If you pass arguments to C<use Log::Any::Adapter>, it calls C<<
Log::Any::Adapter->set >> with those arguments.
=item Log::Any::Adapter->remove (entry)
Remove an I<entry> previously returned by C<set>.
=back
=head1 USING MORE THAN ONE ADAPTER
C<Log::Any> maintains a stack of entries created via C<set>. If you call
C<set> repeatedly, you will leak memory unless you do one of the
following:
=over 4
=item *
call C<remove> on the adapter returned from C<set> when you are done with it
=item *
use the C<lexically> feature to set a guard variable that will clean it up when it goes out of scope
=back
When getting a logger for a particular category, C<Log::Any> will work its way
down the stack and use the first matching entry.
Whenever the stack changes, any C<Log::Any> loggers that have previously been
created will automatically adjust to the new stack. For example:
my $log = Log::Any->get_logger();
$log->error("aiggh!"); # this goes nowhere
...
{
Log::Any::Adapter->set({ lexically => \my $lex }, 'Log4perl');
$log->error("aiggh!"); # this goes to log4perl
...
}
$log->error("aiggh!"); # this goes nowhere again
=head1 SEE ALSO
L<Log::Any|Log::Any>
=head1 AUTHORS
=over 4
=item *
Jonathan Swartz <swartz@pobox.com>
=item *
David Golden <dagolden@cpan.org>
=back
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Jonathan Swartz and David Golden.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=head1 AUTHORS
=over 4
=item *
Jonathan Swartz <swartz@pobox.com>
=item *
David Golden <dagolden@cpan.org>
=back
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Jonathan Swartz and David Golden.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|