Acrux
view release on metacpan or search on metacpan
lib/Acme/Crux/Plugin/Log.pm view on Meta::CPAN
$app->plugin(Log => undef, {provider => 'syslog'});
This option select the provider of logging. Avalabled providers:
C<logger>, C<handler>, C<file> and C<syslog>.
Default: C<logprovider> command line option or C<logprovider> application argument
or C<LogProvider> configuration value or C<file> otherwise
=head2 short
$app->plugin(Log => undef, {short => 1});
Generate short log messages without a timestamp but with log level prefix
Default: C<logshort> command line option or C<logshort> application argument
or C<LogShort> configuration value or C<0> otherwise
=head1 METHODS
This class inherits all methods from L<Acme::Crux::Plugin> and implements the following new ones
=head2 register
$plugin->register($app, {file => '/var/log/app.log'});
Register plugin in Acme::Crux application
=head1 HELPERS
All helpers of this plugin are allows get access to logger object.
See L<Acrux::Log> for details
=head2 log
Returns L<Acrux::Log> object
=head1 TO DO
See C<TODO> file
=head1 SEE ALSO
L<Acme::Crux::Plugin>, L<Acrux::Log>
=head1 AUTHOR
Serż Minus (Sergey Lepenkov) L<https://www.serzik.com> E<lt>abalama@cpan.orgE<gt>
=head1 COPYRIGHT
Copyright (C) 1998-2026 D&D Corporation
=head1 LICENSE
This program is distributed under the terms of the Artistic License Version 2.0
See the C<LICENSE> file or L<https://opensource.org/license/artistic-2-0> for details
=cut
use parent 'Acme::Crux::Plugin';
use Acrux::Log;
use Carp qw/croak/;
use Acrux::RefUtil qw/as_array_ref as_hash_ref is_code_ref is_true_flag is_ref/;
sub register {
my ($self, $app, $args) = @_;
my $has_config = $app->can('config') ? 1 : 0;
# Autoclean flag: PLGARGS || OPTS || ORIG || CONF || DEFS
my $autoclean = is_true_flag($args->{autoclean}) # From plugin arguments first
|| $app->getopt("logautoclean") # From command line options
|| $app->orig->{"logautoclean"} # From App arguments
|| ($has_config ? $app->config->get("/logautoclean") : 0); # From config file
# Colorize flag: PLGARGS || OPTS || ORIG || CONF || DEFS
my $colorize = is_true_flag($args->{color}) # From plugin arguments first
|| $app->getopt("logcolorize") # From command line options
|| $app->orig->{"logcolorize"} # From App arguments
|| ($has_config ? $app->config->get("/logcolorize") : 0); # From config file
# Log facility: PLGARGS || OPTS || ORIG || CONF || DEFS
my $facility = $args->{facility} # From plugin arguments first
|| $app->getopt("logfacility") # From command line options
|| $app->orig->{"logfacility"} # From App arguments
|| ($has_config ? $app->config->get("/logfacility") : ''); # From config file
# Log file: PLGARGS || OPTS || CONF || ORIG || DEFS
my $file = $args->{file} # From plugin arguments first
|| $app->getopt("logfile") # From command line options
|| ($has_config ? $app->config->get("/logfile") : '') # From config file
|| $app->logfile; # From App arguments
# Format: PLGARGS || DEFS
my $frmt = $args->{format} || $app->orig->{"logformat"};
if (defined($frmt) && length($frmt)) {
croak(qq{Invalid log format coderef}) unless is_code_ref($frmt);
}
# Handle: PLGARGS || DEFS
my $handle = $args->{handle} || $app->orig->{"loghandle"};
if (defined $handle) {
croak(qq{Invalid log handle}) unless is_ref($handle);
}
# Log ident: PLGARGS || OPTS || ORIG || CONF || DEFS
my $ident = $args->{ident} # From plugin arguments first
|| $app->getopt("logident") # From command line options
|| $app->orig->{"logident"} # From App arguments
|| ($has_config ? $app->config->get("/logident") : ''); # From config file
# Log level: PLGARGS || OPTS || ORIG || CONF || DEFS
my $level = $args->{level} # From plugin arguments first
|| $app->getopt("loglevel") # From command line options
|| $app->orig->{"loglevel"} # From App arguments
|| ($has_config ? $app->config->get("/loglevel") : ''); # From config file
# Logger: PLGARGS || DEFS
my $logger = $args->{logger} || $app->orig->{"logger"};
( run in 1.325 second using v1.01-cache-2.11-cpan-ceb78f64989 )