blob: a5a7776d092945a3288073fcc37e8f6804b196fe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
package PerlDaemon::ThreadedLogger;
use strict;
use warnings;
$| = 1;
sub new ($$) {
my ($class, $conf) = @_;
my $self = $SELF = bless { conf => $conf }, $class;
return $self;
}
sub _pushmsg ($$) {
my ($self, $msg) = @_;
my $conf = $self->{conf};
my $msgqueue = $conf->{msgqueue};
push @$msgqueue, $msg;
}
sub logmsg ($$) {
my ($self, $msg) = @_;
my $logline = localtime()." (PID $$): $msg\n";
$self->_pushmsg($logline);
return undef;
}
sub err ($$) {
my ($self, $msg) = @_;
$self->logmsg($msg);
die "$msg\n";
}
sub warn ($$) {
my ($self, $msg) = @_;
$self->logmsg("WARNING: $msg");
return undef;
}
1;
|