diff options
| author | Paul Buetow <paul@buetow.org> | 2011-03-17 08:10:11 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2011-03-17 08:10:11 +0000 |
| commit | 450b84bb62277df46fb9c2e0f745c4868c393ce2 (patch) | |
| tree | 6fef966b11e238b14f8d910a6f5da47dc655cd6e /PerlDaemon/Logger.pm | |
| parent | 6406b729d443d8ea133a4a92495b1256e57a8f4d (diff) | |
renamed due module name
Diffstat (limited to 'PerlDaemon/Logger.pm')
| -rw-r--r-- | PerlDaemon/Logger.pm | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/PerlDaemon/Logger.pm b/PerlDaemon/Logger.pm new file mode 100644 index 0000000..fccc274 --- /dev/null +++ b/PerlDaemon/Logger.pm @@ -0,0 +1,40 @@ +package PerlDaemon::Logger; + +use Shell qw(mv); +use POSIX qw(strftime); + +$| = 1; + +sub new ($$) { + my ($class, $conf) = @_; + return bless { conf => $conf }, $class; +} + +sub logmsg ($$) { + my ($self, $msg) = @_; + my $conf = $self->{conf}; + my $logfile = $conf->{'daemon.logfile'}; + + open my $fh, ">>$logfile" or die "Can't write logfile $logfile: $!\n"; + print $fh localtime()." (PID $$): $msg\n"; + close $fh; +} + +sub err ($$) { + my ($self, $msg) = @_; + $self->logmsg($msg); + die "$msg\n"; +} + +sub rotatelog ($) { + my $self = shift; + my $conf = $self->{conf}; + my $logfile = $conf->{'daemon.logfile'}; + + $self->logmsg('Rotating logfile'); + + my $timestr = strftime "%Y%m%d-%H%M%S", localtime(); + mv($logfile, "$logfile.$timestr"); +} + +1; |
