.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" 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" '' '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 turned on, 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. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "MooseX::Log::Log4perl 3pm" .TH MooseX::Log::Log4perl 3pm "2012-06-27" "perl v5.14.2" "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" MooseX::Log::Log4perl \- A Logging Role for Moose based on Log::Log4perl .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& package MyApp; \& use Moose; \& \& with \*(AqMooseX::Log::Log4perl\*(Aq; \& \& sub something { \& my ($self) = @_; \& $self\->log\->debug("started bar"); ### logs with default class catergory "MyApp" \& ... \& $self\->log(\*(Aqspecial\*(Aq)\->info(\*(Aqbar\*(Aq); ### logs with category "special" \& ... \& $self\->log(\*(Aq.special\*(Aq)\->info(\*(Aqbar\*(Aq); ### logs with category "MyApp.special" \& $self\->log(\*(Aq::special\*(Aq)\->info(\*(Aqbar\*(Aq);### logs with category "MyApp.special" \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" A logging role building a very lightweight wrapper to Log::Log4perl for use with your Moose classes. The initialization of the Log4perl instance must be performed prior to logging the first log message. Otherwise the default initialization will happen, probably not doing the things you expect. .PP For compatibility the \f(CW\*(C`logger\*(C'\fR attribute can be accessed to use a common interface for application logging. .PP Using the logger within a class is as simple as consuming a role: .PP .Vb 3 \& package MyClass; \& use Moose; \& with \*(AqMooseX::Log::Log4perl\*(Aq; \& \& sub dummy { \& my $self = shift; \& $self\->log\->info("Dummy log entry"); \& } .Ve .PP The logger needs to be setup before using the logger, which could happen in the main application: .PP .Vb 3 \& package main; \& use Log::Log4perl qw(:easy); \& use MyClass; \& \& BEGIN { Log::Log4perl\->easy_init() }; \& \& my $myclass = MyClass\->new(); \& $myclass\->log\->info("In my class"); # Access the log of the object \& $myclass\->dummy; # Will log "Dummy log entry" .Ve .SH "EVEN SIMPLER USE" .IX Header "EVEN SIMPLER USE" For simple logging needs use MooseX::Log::Log4perl::Easy to directly add log_ methods to your class instance. .PP .Vb 1 \& $self\->log_info("Dummy"); .Ve .SH "USING WITH MOUSE INSTEAD OF MOOSE" .IX Header "USING WITH MOUSE INSTEAD OF MOOSE" As this module is using Any::Moose, you can use it with Mouse instead of Moose too. .PP This will allow to simple use it as documented above in a Mouse based application, like shown in the example below: .PP This is your class consuming the MooseX::Log::Log4perl role. .PP .Vb 2 \& package MyCat; \& use Mouse; \& \& with \*(AqMooseX::Log::Log4perl\*(Aq; \& \& sub catch_it { \& my $self = shift; \& $self\->log\->debug("Say Miau"); \& } .Ve .PP Which can be simply used in your main application then. .PP .Vb 4 \& package main; \& use MyCat; \& use Log::Log4perl qw(:easy); \& BEGIN { Log::Log4perl\->easy_init() }; \& \& my $log = Log::Log4perl\->get_logger(); \& $log\->info("Application startup..."); \& MyCat\->new()\->catch_it(); ### Will log "Dummy dodo" .Ve .SH "ACCESSORS" .IX Header "ACCESSORS" .SS "logger" .IX Subsection "logger" The \f(CW\*(C`logger\*(C'\fR attribute holds the Log::Log4perl object that implements all logging methods for the defined log levels, such as \f(CW\*(C`debug\*(C'\fR or \f(CW\*(C`error\*(C'\fR. As this method is defined also in other logging roles/systems like MooseX::Log::LogDispatch this can be thought of as a common logging interface. .PP .Vb 1 \& package MyApp::View::JSON; \& \& extends \*(AqMyApp::View\*(Aq; \& with \*(AqMooseX:Log::Log4perl\*(Aq; \& \& sub bar { \& $self\->logger\->info("Everything fine so far"); # logs a info message \& $self\->logger\->debug("Something is fishy here"); # logs a debug message \& } .Ve .SS "log([$category])" .IX Subsection "log([$category])" Basically the same as logger, but also allowing to change the log category for this log message. If the category starts with a \f(CW\*(C`+\*(C'\fR, we pre-pend the current class (what would have been the category if you didn't specify one). .PP .Vb 7 \& if ($myapp\->log\->is_debug()) { \& $myapp\->log\->debug("Woot"); # category is class myapp \& } \& $myapp\->log("TempCat")\->info("Foobar"); # category TempCat \& $myapp\->log\->info("Grumble"); # category class again myapp \& $myapp\->log(".TempCat")\->info("Foobar"); # category myapp.TempCat \& $myapp\->log("::TempCat")\->info("Foobar"); # category myapp.TempCat .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Log::Log4perl, Moose, MooseX::LogDispatch .SH "BUGS AND LIMITATIONS" .IX Header "BUGS AND LIMITATIONS" Please report any bugs or feature requests to \&\f(CW\*(C`bug\-moosex\-log4perl@rt.cpan.org\*(C'\fR, or through the web interface at . .PP Or come bother us in \f(CW\*(C`#moose\*(C'\fR on \f(CW\*(C`irc.perl.org\*(C'\fR. .SH "AUTHOR" .IX Header "AUTHOR" Roland Lammel \f(CW\*(C`\*(C'\fR .PP Inspired by the work by Chris Prather \f(CW\*(C`\*(C'\fR and Ash Berlin \f(CW\*(C`\*(C'\fR on MooseX::LogDispatch .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" In alphabetical order: .ie n .IP "Michael Schilli """" for Log::Log4perl and suggestions in the interface." 2 .el .IP "Michael Schilli \f(CW\fR for Log::Log4perl and suggestions in the interface." 2 .IX Item "Michael Schilli for Log::Log4perl and suggestions in the interface." .PD 0 .ie n .IP "Tim Bunce """" for corrections in the MooseX::Log::Log4perl::Easy module." 2 .el .IP "Tim Bunce \f(CW\fR for corrections in the MooseX::Log::Log4perl::Easy module." 2 .IX Item "Tim Bunce for corrections in the MooseX::Log::Log4perl::Easy module." .PD .SH "LICENSE AND COPYRIGHT" .IX Header "LICENSE AND COPYRIGHT" Copyright (c) 2008\-2012, Roland Lammel \f(CW\*(C`\*(C'\fR, http://www.quikit.at .PP This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.