Catmandu::Logger(3pm)
π Catmandu::Logger β the Perl doc you didn't know you needed π
okay bestie, so this is the Catmandu::Logger(3pm) page from the User Contributed Perl Documentation, and it's literally just a little role for classes that need logging capabilities. she's small. she's powerful. she's giving main character energy. let's get into it π«Ά
β¨ NAME β¨
Catmandu::Logger β a role for classes that need logging capabilities. that's it, that's the whole name section, she's concise π
π¦ SYNOPSIS π¦
here's the vibe, no cap:
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");
}
yes the word "catergory" is spelled like that in the original and yes i'm keeping it exactly as-is, bestie, we do not touch the sacred typos π
πΈ DESCRIPTION πΈ
so basically? this is a logging role that builds a very lightweight wrapper around Log::Any. she's not doing too much, she's just vibing as a thin lil layer.
important!! connecting aLog::Any::Adapterhas to happen before you log your first log message. otherwise nothing will happen β like, nothing at all, just silence, which is exactly howLog::Anybehaves too. so do it first, bestie, or your logs are gonna ghost you π
the logger needs to be setup before using the logger. that could happen in the main application, like this:
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 looking 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 for picking which messages get logged and which ones don't. slay β¨
π CATMANDU COMMAND LINE π
when you're using the catmandu command line, you can activate the logger with the -D option β and yes, that works on all Catmandu commands. iconic behaviour honestly.
$ 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 either an inline log4perl configuration or a filename containing the configuration. your choice, bestie, both are valid π
also! see Catmandu::Fix::log for how to include log messages in the Catmandu::Fix language. iykyk π
π ACCESSORS π
π log
the "log" attribute holds the Log::Any::Adapter object that implements all the logging methods for the defined log levels β things like "debug" or "error".
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. and you can 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. pick your level of specificity, queen π
π§ log_category
default is the class name. that's the whole thing. short and sweet, she said what she said π
π SEE ALSO π
Log::Any
and that's the page, bestie!! π«Ά this whole thing comes from perl v5.40.1, dated 2026-01-24, and it's the Catmandu::Logger(3pm) page from the User Contributed Perl Documentation. go forth and log responsibly, mwah πβ¨π
π¦ where this page comes from
- ubuntu resolute: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms