Catalyst::Log(3pm)
π Catalyst::Log β the Catalyst Log Class π
okay bestie, so this is Catalyst::Log(3pm) from the User Contributed Perl Documentation, and it's literally the log class for Catalyst. it's giving "your app is screaming into the void but, like, in a structured way" β¨
πΈ SYNOPSIS πΈ
$log = $c->log;
$log->debug($message);
$log->info($message);
$log->warn($message);
$log->error($message);
$log->fatal($message);
if ( $log->is_debug ) {
# expensive debugging
}
also go look at Catalyst. π
π¦ DESCRIPTION π¦
so this module is the default, simple logging situation for Catalyst. that's it, that's the vibe. but if you want something β¨differentβ¨, you just set $c->log in your application module, like:
$c->log( MyLogger->new );
your logging object is expected to provide the interface described right here in this very page. some good alternatives to consider are Log::Log4Perl and Log::Dispatch. π
now, if you wanna be able to log arbitrary warnings, you can do something along the lines of
$SIG{__WARN__} = sub { MyApp->log->warn(@_); };
but bestie. this is (a) global, (b) hairy, and (c) may have unexpected side effects. don't say we didn't warn you. π no cap.
π LOG LEVELS π
debug
$log->is_debug;
$log->debug($message);
info
$log->is_info;
$log->info($message);
warn
$log->is_warn;
$log->warn($message);
error
$log->is_error;
$log->error($message);
fatal
$log->is_fatal;
$log->fatal($message);
β¨ METHODS β¨
new
the constructor, periodt. defaults to enabling all levels unless you pass levels in the arguments.
$log = Catalyst::Log->new;
$log = Catalyst::Log->new( 'warn', 'error' );
level
this one contains a bitmask of the currently set log levels. it's giving "bitwise but make it fashion" π
levels
set log levels:
$log->levels( 'warn', 'error', 'fatal' );
enable
enable log levels:
$log->enable( 'warn', 'error' );
disable
disable log levels:
$log->disable( 'warn', 'error' );
is_debug
is_error
is_fatal
is_info
is_warn
is the log level active? that's the whole question. yes or no, bestie. π«Ά
abort
should Catalyst emit logs for this request? it gets reset at the end of each request.
*NOTE* this method is not compatible with other log apis, so if you plan to use Log4Perl or another logger, you should call it like this:
$c->log->abort(1) if $c->log->can('abort');
iykyk. π
autoflush
when enabled (that's the default, btw), messages are written to the log immediately instead of being queued until the end of the request.
this option, as well as "abort", is provided for modules such as Catalyst::Plugin::Static::Simple to be able to programmatically suppress the output of log messages. by turning off "autoflush" (application-wide setting) and then setting the "abort" flag within a given request, all log messages for the given request will be suppressed. "abort" can still be set independently of turning off "autoflush", however. it just means any messages sent to the log up until that point in the request will obviously still be emitted, since "autoflush" means they are written in real-time. β°
if you need to turn off autoflush you should do it like this (in your main app class):
after setup_finalize => sub {
my $c = shift;
$c->log->autoflush(0) if $c->log->can('autoflush');
};
_send_to_log
$log->_send_to_log( @messages );
this protected method is what actually sends the log information to STDERR. you may subclass this module and override this method to get finer control over the log output. main character method energy, honestly. π
psgienv $env
$log->psgienv($env);
NOTE: this is not meant for public consumption. π«
set the PSGI environment for this request. this ensures logs will be sent to the right place. if the environment has a "psgix.logger", it will be used. if not, we will send logs to "psgi.errors" if that exists. as a last fallback, we will send to STDERR as before. so many fallbacks, so little time. π§
clear_psgi
clears the PSGI environment attributes set by "psgienv". bye bestie π
meta
(no description in the original, she's mysterious like that π)
β SEE ALSO β
Catalyst.
π AUTHORS π
Catalyst Contributors, see Catalyst.pm. iconic collective behaviour fr fr. π«Ά
π COPYRIGHT π
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, babe β this was perl v5.40.0, dated 2024-11-15, Catalyst::Log(3pm). slay, go log something responsibly. πβ¨π
π¦ where this page comes from
- debian trixie: libcatalyst-perl 5.90132-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcatalyst-perl 5.90132-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatalyst-perl 5.90132-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