lemonldap-ng/lemonldap-ng-common/lib/Lemonldap/NG/Common/Logger/Sentry.pm

39 lines
1.0 KiB
Perl
Raw Normal View History

2018-05-09 21:07:21 +02:00
# EXPERIMENTAL LOGGER
#
# To use it:
# - set logger to Lemonldap::NG::Common::Logger::Sentry
# - set sentryDsn in lemonldap-ng.ini
# - use a high value for logLevel (or userLogger):error or warn, else too
# many issues will be created and service will reject requests
2018-05-09 20:40:11 +02:00
package Lemonldap::NG::Common::Logger::Sentry;
use strict;
use Sentry::Raven;
our $VERSION = '2.0.0';
sub new {
my $self = bless {}, shift;
my ($conf) = @_;
my $show = 1;
2018-05-09 21:07:21 +02:00
$self->{raven} = Sentry::Raven->new( sentry_dsn => $conf->{sentryDsn} );
2018-05-09 20:40:11 +02:00
foreach (qw(error warn notice info debug)) {
my $rl = $_;
$rl = 'warning' if ( $rl = 'warn' );
$rl = 'info' if ( $rl = 'notice' );
if ($show) {
eval
2018-05-09 21:07:21 +02:00
qq'sub $_ {\$_[0]->{raven}->capture_message(\$_[1],level => "$rl")}';
2018-06-21 21:35:16 +02:00
die $@ if ($@);
2018-05-09 20:40:11 +02:00
}
else {
eval qq'sub $_ {1}';
}
2018-05-09 21:07:21 +02:00
$show = 0 if ( $conf->{logLevel} eq $_ );
2018-05-09 20:40:11 +02:00
}
2018-05-09 21:07:21 +02:00
die "unknown level $conf->{logLevel}" if ($show);
2018-05-09 20:40:11 +02:00
return $self;
}
1;