Catalyst::Log(3pm)

πŸ“¦
version 5.90132 Β· 6 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– 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. 🫢


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