Initial Commit

This commit is contained in:
Riley Schneider
2025-12-03 16:38:10 +01:00
parent c5e26bf594
commit b732d8d4b5
17680 changed files with 5977495 additions and 2 deletions

View File

@@ -0,0 +1,88 @@
# Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
# For other contributors see ChangeLog.
# See the manual pages for details on the licensing terms.
# Pod stripped from pm file by OODoc 2.02.
# This code is part of distribution Log-Report. Meta-POD processed with
# OODoc into POD and HTML manual-pages. See README.md
# Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
package Dancer2::Logger::LogReport;
use vars '$VERSION';
$VERSION = '1.31';
# ABSTRACT: Dancer2 logger engine for Log::Report
use strict;
use warnings;
use Moo;
use Dancer2::Core::Types;
use Scalar::Util qw/blessed/;
use Log::Report 'log-report', syntax => 'REPORT';
our $AUTHORITY = 'cpan:MARKOV';
my %level_dancer2lr =
( core => 'TRACE'
, debug => 'TRACE'
);
with 'Dancer2::Core::Role::Logger';
# Set by calling function
has dispatchers =>
( is => 'ro'
, isa => Maybe[HashRef]
);
sub BUILD
{ my $self = shift;
my $configs = $self->dispatchers || {default => undef};
$self->{use} = [keys %$configs];
dispatcher 'do-not-reopen';
foreach my $name (keys %$configs)
{ my $config = $configs->{$name} || {};
if(keys %$config)
{ my $type = delete $config->{type}
or die "dispatcher configuration $name without type";
dispatcher $type, $name, %$config;
}
}
}
around 'error' => sub {
my ($orig, $self) = (shift, shift);
# If it's a route exception (generated by Dancer) and we're also using the
# Plugin, then the plugin will handle the exception using its own hook into
# the error system. This should be able to removed in the future with
# https://github.com/PerlDancer/Dancer2/pull/1287
return if $_[0] =~ /^Route exception/
&& $INC{'Dancer2/Plugin/LogReport.pm'};
$self->log(error => @_);
};
sub log # no protoypes in Dancer2
{ my ($self, $level, $msg) = @_;
my %options;
# If only using the logger on its own (without the associated plugin), make
# it behave like a normal Dancer logger
unless ($INC{'Dancer2/Plugin/LogReport.pm'})
{ $msg = $self->format_message($level, $msg);
$options{is_fatal} = 0;
}
# the levels are nearly the same.
my $reason = $level_dancer2lr{$level} || uc $level;
report \%options, $reason => $msg;
undef;
}
1;

View File

@@ -0,0 +1,84 @@
=encoding utf8
=head1 NAME
Dancer2::Logger::LogReport - reroute Dancer2 logs into Log::Report
=head1 INHERITANCE
Dancer2::Logger::LogReport
is a Moo::Object
=head1 SYNOPSIS
# This module is loaded when configured. It does not provide
# end-user functions or methods.
# See DETAILS
=head1 DESCRIPTION
[The Dancer2 plugin was contributed by Andrew Beverley]
This logger allows the use of the many logging backends available
in L<Log::Report|Log::Report>. It will process all of the Dancer2 log messages,
and also allow any other module to use the same logging facilities. The
same log messages can be sent to multiple destinations at the same time
via flexible dispatchers.
If using this logger, you may also want to use
L<Dancer2::Plugin::LogReport|Dancer2::Plugin::LogReport>
Many log back-ends, like syslog, have more levels of system messages.
Modules who explicitly load this module can use the missing C<assert>,
C<notice>, C<panic>, and C<alert> log levels. The C<trace> name is
provided as well: when you are debugging, you add a 'trace' to your
program... it's just a better name than 'debug'. You will need to load
Log::Report in order to use the additional levels; if doing so directly within
a Dancer2 application (not a sub-module), then you will either need to load
Log::Report with C<syntax, 'LONG'> or use L<Dancer2::Plugin::LogReport|Dancer2::Plugin::LogReport> to
prevent namespace clashes.
=head2 Log Format
If using this module on its own (such as a drop-in replacement for
Dancer2::Logger::Syslog), then the logging format is configured as with any
other Dancer logger. If using this module with L<Dancer2::Plugin::LogReport|Dancer2::Plugin::LogReport>,
then log_format is ignored and messages are not formatted, in order to keep the
message format consistent regardless of where the message was generated (be it
another module using Log::Report, the plugin, or Dancer itself). In this case,
the log format should be configured using the applicable dispatcher (such as
L<Log::Report::Dispatcher::Syslog::new(format)|Log::Report::Dispatcher::Syslog/"Constructors">).
If also using with the L<Log::Report> logging functions, then you probably want
to set a very simple C<logger_format>, because the dispatchers do already add
some of the fields that the default C<simple> format adds. For instance, to
get the filename/line-number in messages depends on the dispatcher 'mode' (f.i.
'DEBUG').
You also want to set the Dancer2 log level to C<debug>, because level filtering
is controlled per dispatcher (as well).
See L<Dancer2::Plugin::LogReport/"DETAILS"> for examples.
=head1 METHODS
=over 4
=item $obj-E<gt>B<log>($level, $params)
=back
=head1 SEE ALSO
This module is part of Log-Report distribution version 1.31,
built on January 15, 2021. Website: F<http://perl.overmeer.net/CPAN/>
=head1 LICENSE
Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
See F<http://dev.perl.org/licenses/>