Subversion Repositories DevTools

Rev

Rev 1038 | Rev 1289 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1044 dpurdie 1
########################################################################
2
# Copyright (C) 1998-2011 Vix Technology, All rights reserved
3
#
4
# Module name   : StdLogger.pm
5
# Module type   :
6
# Compiler(s)   : Perl
7
# Environment(s):
8
#
9
# Description   : Dummy logger
10
#                 Logs to a file
11
#
12
#......................................................................#
13
 
14
require 5.008_002;
15
use strict;
16
use warnings;
1038 dpurdie 17
package Logger;
18
 
19
use Shell qw(mv);
20
 
21
$| = 1;
22
 
23
sub new ($$) {
24
	my ($class, $conf) = @_;
25
	return bless { conf => $conf }, $class;
26
}
27
 
28
sub logmsg ($$) {
29
	my ($self, $msg) = @_;
30
	my $conf = $self->{conf};
31
	my $logfile = $conf->{'logfile'};
32
 
33
	open my $fh, ">>$logfile" or die "Can't write blat logfile $logfile: $!\n";
34
	print $fh localtime()." (PID $$): $msg\n";
35
    close $fh;
36
 
37
    unless ( $self->{RollingLogs} )
38
    {
39
        #
40
        #   Is it time to roll the log file
41
        #
42
        my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
43
           $atime,$mtime,$ctime,$blksize,$blocks) = stat($logfile);
44
 
45
        if ( $size > $conf->{'logfile.size'} )
46
        {
47
            rotatelog($self);
48
        }
49
    }
50
 
51
    return undef;
52
}
53
 
54
sub err ($$) {
55
	my ($self, $msg) = @_;
56
	$self->logmsg("ERROR: $msg");
57
    $SIG{__DIE__} = undef;
58
	die "ERROR: $msg\n";
59
}
60
 
61
sub warn ($$) {
62
	my ($self, $msg) = @_;
63
	$self->logmsg("WARNING: $msg");
64
    return undef;
65
}
66
 
67
sub verbose ($$) {
68
    my $self = shift;
69
	my $conf = $self->{conf};
70
	$self->logmsg("(V): @_") if ( $conf->{verbose} > 0 );
71
    return undef;
72
}
73
 
74
sub verbose2 ($$) {
75
    my $self = shift;
76
	my $conf = $self->{conf};
77
	$self->logmsg("(V): @_") if ( $conf->{verbose} > 1 );
78
    return undef;
79
}
80
 
81
sub verbose3 ($$) {
82
    my $self = shift;
83
	my $conf = $self->{conf};
84
	$self->logmsg("(V): @_") if ( $conf->{verbose} > 2 );
85
    return undef;
86
}
87
 
88
 
89
sub rotatelog ($) {
90
	my $self = shift;
91
	my $conf = $self->{conf};
92
	my $logfile = $conf->{'logfile'};
93
    $self->{RollingLogs} = 1;
94
 
95
	$self->logmsg('Rotating logfile');
96
    my $num = $conf->{'logfile.count'};
97
    unlink "$logfile.$num" if ( -f "$logfile.$num");;
98
    for (; $num > 1 ; $num--)
99
    {
100
        my $prev = $num - 1;
101
        mv ("$logfile.$prev", "$logfile.$num") if ( -f "$logfile.$prev");
102
    }
103
    mv ($logfile, "$logfile.$num");
104
	$self->logmsg('Rotating logfile complete');
105
    $self->{RollingLogs} = 0;
106
    return undef;
107
}
108
 
109
1;