-
-
21 Mar 2022 15:23:34 UTC
- Distribution: Catmandu
- Module version: 1.2019
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (36)
- Testers (334 / 0 / 5)
- Kwalitee
Bus factor: 4- 87.59% Coverage
- License: perl_5
- Perl: v5.14.0
- Activity
24 month- Tools
- Download (814.59KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 19 contributors- Nicolas Steenlant, C<< <nicolas.steenlant at ugent.be> >>
-
Christian Pietsch
-
Dave Sherohman
-
Doug Bell
-
EC2 Default User
-
Jakob Voß
-
Johann Rolschewski
-
Magnus Enger
-
Matthias Vandermaesen
-
Mohammad S Anwar
-
Nicolas Franck
-
Patrick Hochstenbach
-
Pieter De Praetere
-
Snorri Briem
-
Stefan Weil
-
Tom Hukins
-
Upasana Shukla
-
Vitali Peil
-
Zakariyya Mughal
- Dependencies
- Any::URI::Escape
- App::Cmd
- CGI::Expand
- Class::Method::Modifiers
- Clone
- Config::Onion
- Cpanel::JSON::XS
- Data::Compare
- Data::Util
- HTTP::Request
- Hash::Merge::Simple
- IO::Handle::Util
- LWP::UserAgent
- List::MoreUtils
- Log::Any
- Log::Any::Adapter
- MIME::Types
- Module::Build
- Module::Info
- Moo
- MooX::Aliases
- Package::Stash
- Parser::MGC
- Path::Iterator::Rule
- Path::Tiny
- Role::Tiny
- Role::Tiny::With
- String::CamelCase
- Sub::Exporter
- Sub::Quote
- Text::CSV
- Text::Hogan::Compiler
- Throwable
- Time::HiRes
- Try::Tiny::ByClass
- URI
- URI::Template
- UUID::Tiny
- Unicode::Normalize
- YAML::XS
- asa
- namespace::clean
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Catmandu::Logger - A role for classes that need logging capabilities
SYNOPSIS
package MyApp::View; use Moo; with 'Catmandu::Logger'; sub something { my ($self) = @_; $self->log->debug("started bar"); # logs with default class catergory "MyApp::View" $self->log->error("started bar"); }
DESCRIPTION
A logging role building a very lightweight wrapper to Log::Any. Connecting a Log::Any::Adapter should be performed prior to logging the first log message, otherwise nothing will happen, just like with Log::Any.
The logger needs to be setup before using the logger, which could happen in the main application:
package main; use Log::Any::Adapter; use Log::Log4perl; Log::Any::Adapter->set('Log4perl'); Log::Log4perl::init('./log4perl.conf'); my $app = MyApp::View->new; $app->something(); # will print debug and error messages
with log4perl.conf like:
log4perl.rootLogger=DEBUG,OUT log4perl.appender.OUT=Log::Log4perl::Appender::Screen log4perl.appender.OUT.stderr=1 log4perl.appender.OUT.utf8=1 log4perl.appender.OUT.layout=PatternLayout log4perl.appender.OUT.layout.ConversionPattern=%d [%P] - %p %l time=%r : %m%n
See Log::Log4perl for more configuration options and selecting which messages to log and which not.
CATMANDU COMMAND LINE
When using the catmandu command line, the logger can be activated using the -D option on all Catmandu commands:
$ catmandu -D convert JSON to YAML < data.json $ catmandu -D export MongoDB --database-name items --bag
The log4perl configuration for the
catmandu
command line must be defined in a 'catmandu.yml' configuration file:$ cat catmandu.yml log4perl: | log4perl.rootLogger=DEBUG,OUT log4perl.appender.OUT=Log::Log4perl::Appender::Screen log4perl.appender.OUT.stderr=1 log4perl.appender.OUT.utf8=1 log4perl.appender.OUT.layout=PatternLayout log4perl.appender.OUT.layout.ConversionPattern=%d [%P] - %p %l time=%r : %m%n
The
log4perl
section can point to an inline log4perl configuration or a filename containing the configuration.See Catmandu::Fix::log how to include log messages in the Catmandu::Fix language.
ACCESSORS
log
The
log
attribute holds the Log::Any::Adapter object that implements all logging methods for the defined log levels, such asdebug
orerror
.package MyApp::View::JSON; extends 'MyApp::View'; with 'Catmandu::Logger'; sub bar { $self->log->info("Everything fine so far"); # logs a info message $self->log->debug("Something is fishy here"); # logs a debug message }
Your package automatically has a logging category of MyApp::View::JSON. Use lines like:
log4perl.logger.MyApp::View::JSON=DEBUG,STDOUT
or
log4perl.logger.MyApp::View=DEBUG,STDOUT
or
log4perl.logger.MyApp=DEBUG,STDOUT
for specialized logging for your application.
log_category
Default is the class name.
SEE ALSO
Module Install Instructions
To install Catmandu, copy and paste the appropriate command in to your terminal.
cpanm Catmandu
perl -MCPAN -e shell install Catmandu
For more information on module installation, please visit the detailed CPAN module installation guide.