.\" 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 "MooseX::Log::Log4perl 3pm" .TH MooseX::Log::Log4perl 3pm "2022-06-15" "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" 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 or Moo 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 MOO INSTEAD OF MOOSE" .IX Header "USING WITH MOO INSTEAD OF MOOSE" As this module is using Moo, you can use it with Moo instead of Moose too. .PP This will allow you to simply use it as documented above in a Moo 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 Moo; \& \& 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, Moo, MooX::Log::Any, MooX::Role::Logger .SH "BUGS AND LIMITATIONS" .IX Header "BUGS AND LIMITATIONS" Please report any issues 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 .PP Inspired by the work by Chris Prather and Ash Berlin on MooseX::LogDispatch .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" In alphabetical order: .IP "\(bu" 2 abraxxa for Any::Moose deprectation .IP "\(bu" 2 Michael Schilli for Log::Log4perl and interface suggestions .IP "\(bu" 2 omega for catgory prefix support .IP "\(bu" 2 Tim Bunce for corrections in the MooseX::Log::Log4perl::Easy module. .SH "LICENSE AND COPYRIGHT" .IX Header "LICENSE AND COPYRIGHT" Copyright (c) 2008\-2016, Roland Lammel , .PP This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.