Rev 3846 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
######################################################################### Copyright (C) 1998-2011 Vix Technology, All rights reserved## Module name : StdLogger.pm# Module type :# Compiler(s) : Perl# Environment(s):## Description : Dummy logger# Logs to a file##......................................................................#require 5.008_002;use strict;use warnings;package Logger;$| = 1;sub new ($$) {my ($class, $conf) = @_;return bless { conf => $conf }, $class;}sub logmsg ($$) {my ($self, $msg) = @_;my $conf = $self->{conf};if ($conf->{debug}) {print($msg, "\n");}my $logfile = $conf->{'logfile'};open my $fh, ">>$logfile" or die "Can't write blat logfile $logfile: $!\n";$msg =~ s~\s+$~~;print $fh localtime()." (PID $$): $msg\n";close $fh;unless ( $self->{RollingLogs} ){## Is it time to roll the log file#my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($logfile);if ( $size > $conf->{'logfile.size'} ){rotatelog($self);}}return undef;}sub err ($$) {my ($self, $msg) = @_;$self->logmsg("ERROR: $msg");$SIG{__WARN__} = undef;$SIG{__DIE__} = undef;die "ERROR: $msg\n";}sub warn ($$) {my ($self, $msg) = @_;$self->logmsg("WARNING: $msg");return undef;}sub verbose ($$) {my $self = shift;my $conf = $self->{conf};$self->logmsg("(V): @_") if ( $conf->{verbose} > 0 );return undef;}sub verbose2 ($$) {my $self = shift;my $conf = $self->{conf};$self->logmsg("(V): @_") if ( $conf->{verbose} > 1 );return undef;}sub verbose3 ($$) {my $self = shift;my $conf = $self->{conf};$self->logmsg("(V): @_") if ( $conf->{verbose} > 2 );return undef;}sub rotatelog ($) {my $self = shift;my $conf = $self->{conf};my $logfile = $conf->{'logfile'};$self->{RollingLogs} = 1;$self->logmsg('Rotating logfile');my $num = $conf->{'logfile.count'};unlink "$logfile.$num" if ( -f "$logfile.$num");;for (; $num > 1 ; $num--){my $prev = $num - 1;rename ("$logfile.$prev", "$logfile.$num") if ( -f "$logfile.$prev");}rename ($logfile, "$logfile.$num");$self->logmsg('Rotating logfile complete');$self->{RollingLogs} = 0;return undef;}1;