diff options
| author | Paul Buetow <paul@buetow.org> | 2011-05-13 14:04:27 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2011-05-13 14:04:27 +0000 |
| commit | 73af1eb840720cf21c420c9a38021f6aa2f41b8f (patch) | |
| tree | e73577e5b615837355d7171a1e1e8942f5c40824 /lib/Logger.pm | |
| parent | d4f295dd34384b71acc6c8c12076719f9bc97c0f (diff) | |
copied stuff into ./lib
Diffstat (limited to 'lib/Logger.pm')
| -rw-r--r-- | lib/Logger.pm | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/Logger.pm b/lib/Logger.pm new file mode 100644 index 0000000..fccc274 --- /dev/null +++ b/lib/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; |
