• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

inc/Module/H08-Dec-2015-3,1352,352

lib/MooseX/Log/H08-Dec-2015-31435

t/H08-Dec-2015-423326

ChangesH A D08-Dec-20152.4 KiB5745

MANIFESTH A D27-Jun-2012558 2827

META.ymlH A D08-Dec-2015796 3332

Makefile.PLH A D03-May-2022255 159

READMEH A D08-Dec-20154.7 KiB171120

README

1NAME
2----
3
4    MooseX::Log::Log4perl - A Logging Role for Moose based on Log::Log4perl
5
6SYNOPSIS
7--------
8
9        package MyApp;
10        use Moose;
11
12        with 'MooseX::Log::Log4perl';
13
14        sub something {
15            my ($self) = @_;
16            $self->log->debug("started bar");    ### logs with default class catergory "MyApp"
17            ...
18            $self->log('special')->info('bar');  ### logs with category "special"
19            ...
20            $self->log('.special')->info('bar'); ### logs with category "MyApp.special"
21            $self->log('::special')->info('bar');### logs with category "MyApp.special"
22        }
23
24DESCRIPTION
25-----------
26
27A logging role building a very lightweight wrapper to Log::Log4perl for
28use with your Moose or Moo classes. The initialization of the Log4perl
29instance must be performed prior to logging the first log message.
30Otherwise the default initialization will happen, probably not doing the
31things you expect.
32
33For compatibility the "logger" attribute can be accessed to use a common
34interface for application logging.
35
36Using the logger within a class is as simple as consuming a role:
37
38    package MyClass;
39    use Moose;
40    with 'MooseX::Log::Log4perl';
41
42    sub dummy {
43        my $self = shift;
44        $self->log->info("Dummy log entry");
45    }
46
47The logger needs to be setup before using the logger, which could happen
48in the main application:
49
50    package main;
51    use Log::Log4perl qw(:easy);
52    use MyClass;
53
54    BEGIN { Log::Log4perl->easy_init() };
55
56    my $myclass = MyClass->new();
57    $myclass->log->info("In my class"); # Access the log of the object
58    $myclass->dummy;                    # Will log "Dummy log entry"
59
60EVEN SIMPLER USE
61----------------
62
63For simple logging needs use MooseX::Log::Log4perl::Easy to directly add
64log_<level> methods to your class instance.
65
66    $self->log_info("Dummy");
67
68USING WITH MOO INSTEAD OF MOOSE
69-------------------------------
70
71As this module is using Moo, you can use it with Moo instead of Moose too.
72This will allow to simple use it as documented above in a Moo based application,
73like shown in the example below:
74
75This is your class consuming the MooseX::Log::Log4perl role.
76
77    package MyCat;
78    use Moo;
79
80    with 'MooseX::Log::Log4perl';
81
82    sub catch_it {
83        my $self = shift;
84        $self->log->debug("Say Miau");
85    }
86
87Which can be simply used in your main application then.
88
89    package main;
90    use MyCat;
91    use Log::Log4perl qw(:easy);
92    BEGIN { Log::Log4perl->easy_init() };
93
94    my $log = Log::Log4perl->get_logger();
95    $log->info("Application startup...");
96    MyCat->new()->catch_it();   ### Will log "Dummy dodo"
97
98ACCESSORS
99---------
100
101### logger
102
103The "logger" attribute holds the Log::Log4perl object that implements all
104logging methods for the defined log levels, such as "debug" or "error". As
105this method is defined also in other logging roles/systems like
106MooseX::Log::LogDispatch this can be thought of as a common logging
107interface.
108
109    package MyApp::View::JSON;
110
111    extends 'MyApp::View';
112    with 'MooseX:Log::Log4perl';
113
114    sub bar {
115      $self->logger->info("Everything fine so far");    # logs a info message
116      $self->logger->debug("Something is fishy here");  # logs a debug message
117    }
118
119### log([$category])
120
121Basically the same as logger, but also allowing to change the log category
122for this log message. If the category starts with a "+", we pre-pend the
123current class (what would have been the category if you didn't specify
124one).
125
126     if ($myapp->log->is_debug()) {
127         $myapp->log->debug("Woot"); # category is class myapp
128     }
129     $myapp->log("TempCat")->info("Foobar"); # category TempCat
130     $myapp->log->info("Grumble"); # category class again myapp
131     $myapp->log(".TempCat")->info("Foobar"); # category myapp.TempCat
132     $myapp->log("::TempCat")->info("Foobar"); # category myapp.TempCat
133
134SEE ALSO
135--------
136
137Log::Log4perl, Moose, Moo, MooX::Log::Any, MooX::Role::Logger
138
139BUGS AND LIMITATIONS
140--------------------
141
142Please report any issues at <https://github.com/lammel/moosex-log-log4perl>
143
144Or come bother us in "#moose" on "irc.perl.org".
145
146AUTHOR
147-------
148
149Roland Lammel <lammel@cpan.org>
150
151Inspired by the work by Chris Prather <perigrin@cpan.org> and Ash Berlin
152<ash@cpan.org> on MooseX::LogDispatch
153
154CONTRIBUTORS
155------------
156
157In alphabetical order:
158
159* abraxxa for Any::Moose deprectation
160* Michael Schilli <m@perlmeister.com> for Log::Log4perl and interface suggestions
161* omega for catgory prefix support
162* Tim Bunce <TIMB@cpan.org> for corrections in the MooseX::Log::Log4perl::Easy module.
163
164LICENSE AND COPYRIGHT
165---------------------
166
167Copyright (c) 2008-2016, Roland Lammel <lammel@cpan.org>, http://www.quikit.at
168
169This module is free software; you can redistribute it and/or modify it
170under the same terms as Perl itself. See perlartistic.
171