.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "MooX::Role::Logger 3pm" .TH MooX::Role::Logger 3pm "2022-06-16" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" MooX::Role::Logger \- Provide logging via Log::Any .SH "VERSION" .IX Header "VERSION" version 0.005 .SH "SYNOPSIS" .IX Header "SYNOPSIS" In your modules: .PP .Vb 3 \& package MyModule; \& use Moose; \& with \*(AqMooX::Role::Logger\*(Aq; \& \& sub run { \& my ($self) = @_; \& $self\->cry; \& } \& \& sub cry { \& my ($self) = @_; \& $self\->_logger\->info("I\*(Aqm sad"); \& } .Ve .PP In your application: .PP .Vb 2 \& use MyModule; \& use Log::Any::Adapter (\*(AqFile\*(Aq, \*(Aq/path/to/file.log\*(Aq); \& \& MyModule\->run; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This role provides universal logging via Log::Any. The class using this role doesn't need to know or care about the details of log configuration, implementation or destination. .PP 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. .PP The application that ultimately uses your module can then choose to direct log messages somewhere based on its own needs and configuration with Log::Any::Adapter. .PP This role is based on Moo so it should work with either Moo or Moose based classes. .SH "USAGE" .IX Header "USAGE" .SS "Testing" .IX Subsection "Testing" Testing with Log::Any is pretty easy, thanks to Log::Any::Test. Just load that before Log::Any loads and your log messages get sent to a test adapter that includes testing methods: .PP .Vb 3 \& use Test::More 0.96; \& use Log::Any::Test; \& use Log::Any qw/$log/; \& \& use lib \*(Aqt/lib\*(Aq; \& use MyModule; \& \& MyModule\->new\->cry; \& $log\->contains_ok( qr/I\*(Aqm sad/, "got log message" ); \& \& done_testing; .Ve .SS "Customizing" .IX Subsection "Customizing" If you have a whole set of classes that should log with a single category, create your own role and set the \f(CW\*(C`_build_\|_logger_category\*(C'\fR there: .PP .Vb 3 \& package MyLibrary::Role::Logger; \& use Moo::Role; \& with \*(AqMooX::Role::Logger\*(Aq; \& \& sub _build_\|_logger_category { "MyLibrary" } .Ve .PP Then in your other classes, use your custom role: .PP .Vb 3 \& package MyLibrary::Foo; \& use Moo; \& with \*(AqMyLibrary::Role::Logger\*(Aq .Ve .SH "METHODS" .IX Header "METHODS" .SS "_logger" .IX Subsection "_logger" Returns a logging object. See Log::Any for a list of logging methods it accepts. .SS "_build_\|_logger_category" .IX Subsection "_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: .PP .Vb 1 \& sub _build_\|_logger_category { _\|_PACKAGE_\|_ } .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Since MooX::Role::Logger is universal, you have to use it with one of several Log::Any::Adapter classes: .IP "\(bu" 4 Log::Any::Adapter::File .IP "\(bu" 4 Log::Any::Adapter::Stderr .IP "\(bu" 4 Log::Any::Adapter::Stdout .IP "\(bu" 4 Log::Any::Adapter::ScreenColoredLevel .IP "\(bu" 4 Log::Any::Adapter::Dispatch .IP "\(bu" 4 Log::Any::Adapter::Syslog .IP "\(bu" 4 Log::Any::Adapter::Log4perl .PP These other logging roles are specific to particular logging packages, rather than being universal: .IP "\(bu" 4 MooseX::LazyLogDispatch .IP "\(bu" 4 MooseX::Log::Log4perl .IP "\(bu" 4 MooseX::LogDispatch .IP "\(bu" 4 MooseX::Role::LogHandler .IP "\(bu" 4 MooseX::Role::Loggable (uses Log::Dispatchouli) .IP "\(bu" 4 Role::Log::Syslog::Fast .SH "SUPPORT" .IX Header "SUPPORT" .SS "Bugs / Feature Requests" .IX Subsection "Bugs / Feature Requests" Please report any bugs or feature requests through the issue tracker at . You will be notified automatically of any progress on your issue. .SS "Source Code" .IX Subsection "Source Code" This is open source software. The code repository is available for public review and contribution under the terms of the license. .PP .PP .Vb 1 \& git clone https://github.com/dagolden/MooX\-Role\-Logger.git .Ve .SH "AUTHOR" .IX Header "AUTHOR" David Golden .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is Copyright (c) 2013 by David Golden. .PP This is free software, licensed under: .PP .Vb 1 \& The Apache License, Version 2.0, January 2004 .Ve