diff options
| author | Paul Buetow <paul@buetow.org> | 2011-03-17 08:02:27 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2011-03-17 08:02:27 +0000 |
| commit | c0c2d506b4151a38178321e94276836dde52d169 (patch) | |
| tree | 0e867b0edf54b0950fd7ac05b61d276ad305c458 /lib/Logger.pm | |
| parent | ee5e8bcb9b436c38f826304d49debf9d770bc877 (diff) | |
./lib and ./conf added.
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..f6c16e8 --- /dev/null +++ b/lib/Logger.pm @@ -0,0 +1,40 @@ +package 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; |
