DoctorKarma/lib/DoctorKarma/Logger.pm

40 lines
644 B
Perl
Raw Permalink Normal View History

2022-02-07 00:30:41 +01:00
package DoctorKarma::Logger;
use Carp;
use Sys::Syslog;
sub new {
my $class = shift;
my $self = bless {}, $class;
return $self;
}
sub _log {
my $self = shift;
my $level = shift;
my $message = shift;
my $critical = shift;
openlog ('DoctorKarma', $critical ? '': 'perror', 'user');
syslog ($level, $message);
closelog();
}
sub log_error {
my $self = shift;
$self->_log (LOG_ERR, shift);
}
sub log_critical {
my $self = shift;
my $error = shift;
$self->_log (LOG_ERR, $error, 1);
confess $error;
}
sub log_info {
my $self = shift;
$self->_log (LOG_INFO, shift);
}
1;