/usr/share/perl5/MooX/Role/Logger.pm is in libmoox-role-logger-perl 0.005-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 | use strict;
use warnings;
package MooX::Role::Logger;
# ABSTRACT: Provide logging via Log::Any
our $VERSION = '0.005'; # VERSION
use Moo::Role;
use Log::Any ();
#pod =method _logger
#pod
#pod Returns a logging object. See L<Log::Any> for a list of logging methods it accepts.
#pod
#pod =cut
has _logger => (
is => 'lazy',
isa => sub { ref( $_[0] ) =~ /^Log::Any/ }, # XXX too many options
init_arg => undef,
);
sub _build__logger {
my ($self) = @_;
return Log::Any->get_logger( category => "" . $self->_logger_category );
}
has _logger_category => ( is => 'lazy', );
#pod =method _build__logger_category
#pod
#pod Override to set the category used for logging. Defaults to the class name of
#pod the object (which could be a subclass). You can override to lock it to a
#pod particular name:
#pod
#pod sub _build__logger_category { __PACKAGE__ }
#pod
#pod =cut
sub _build__logger_category { return ref $_[0] }
1;
# vim: ts=4 sts=4 sw=4 et:
__END__
=pod
=encoding UTF-8
=head1 NAME
MooX::Role::Logger - Provide logging via Log::Any
=head1 VERSION
version 0.005
=head1 SYNOPSIS
In your modules:
package MyModule;
use Moose;
with 'MooX::Role::Logger';
sub run {
my ($self) = @_;
$self->cry;
}
sub cry {
my ($self) = @_;
$self->_logger->info("I'm sad");
}
In your application:
use MyModule;
use Log::Any::Adapter ('File', '/path/to/file.log');
MyModule->run;
=head1 DESCRIPTION
This role provides universal logging via L<Log::Any>. The class using this
role doesn't need to know or care about the details of log configuration,
implementation or destination.
Use it when you want your module to offer logging capabilities, but don't know
who is going to use your module or what kind of logging they will implement.
This role lets you do your part and leaves actual log setup and routing to
someone else.
The application that ultimately uses your module can then choose to direct log
messages somewhere based on its own needs and configuration with
L<Log::Any::Adapter>.
This role is based on L<Moo> so it should work with either L<Moo> or L<Moose>
based classes.
=head1 USAGE
=head2 Testing
Testing with L<Log::Any> is pretty easy, thanks to L<Log::Any::Test>.
Just load that before L<Log::Any> loads and your log messages get
sent to a test adapter that includes testing methods:
use Test::More 0.96;
use Log::Any::Test;
use Log::Any qw/$log/;
use lib 't/lib';
use MyModule;
MyModule->new->cry;
$log->contains_ok( qr/I'm sad/, "got log message" );
done_testing;
=head2 Customizing
If you have a whole set of classes that should log with a single category,
create your own role and set the C<_build__logger_category> there:
package MyLibrary::Role::Logger;
use Moo::Role;
with 'MooX::Role::Logger';
sub _build__logger_category { "MyLibrary" }
Then in your other classes, use your custom role:
package MyLibrary::Foo;
use Moo;
with 'MyLibrary::Role::Logger'
=head1 METHODS
=head2 _logger
Returns a logging object. See L<Log::Any> for a list of logging methods it accepts.
=head2 _build__logger_category
Override to set the category used for logging. Defaults to the class name of
the object (which could be a subclass). You can override to lock it to a
particular name:
sub _build__logger_category { __PACKAGE__ }
=head1 SEE ALSO
Since MooX::Role::Logger is universal, you have to use it with one of
several L<Log::Any::Adapter> classes:
=over 4
=item *
L<Log::Any::Adapter::File>
=item *
L<Log::Any::Adapter::Stderr>
=item *
L<Log::Any::Adapter::Stdout>
=item *
L<Log::Any::Adapter::ScreenColoredLevel>
=item *
L<Log::Any::Adapter::Dispatch>
=item *
L<Log::Any::Adapter::Syslog>
=item *
L<Log::Any::Adapter::Log4perl>
=back
These other logging roles are specific to particular logging packages, rather
than being universal:
=over 4
=item *
L<MooseX::LazyLogDispatch>
=item *
L<MooseX::Log::Log4perl>
=item *
L<MooseX::LogDispatch>
=item *
L<MooseX::Role::LogHandler>
=item *
L<MooseX::Role::Loggable> (uses L<Log::Dispatchouli>)
=item *
L<Role::Log::Syslog::Fast>
=back
=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
=head1 SUPPORT
=head2 Bugs / Feature Requests
Please report any bugs or feature requests through the issue tracker
at L<https://github.com/dagolden/MooX-Role-Logger/issues>.
You will be notified automatically of any progress on your issue.
=head2 Source Code
This is open source software. The code repository is available for
public review and contribution under the terms of the license.
L<https://github.com/dagolden/MooX-Role-Logger>
git clone https://github.com/dagolden/MooX-Role-Logger.git
=head1 AUTHOR
David Golden <dagolden@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2013 by David Golden.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
=cut
|