Subversion Repositories DevTools

Rev

Rev 1044 | Rev 3846 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1044 Rev 1289
Line 19... Line 19...
19
use Shell qw(mv);
19
use Shell qw(mv);
20
 
20
 
21
$| = 1;
21
$| = 1;
22
 
22
 
23
sub new ($$) {
23
sub new ($$) {
24
	my ($class, $conf) = @_;
24
    my ($class, $conf) = @_;
25
	return bless { conf => $conf }, $class;
25
    return bless { conf => $conf }, $class;
26
}
26
}
27
 
27
 
28
sub logmsg ($$) {
28
sub logmsg ($$) {
29
	my ($self, $msg) = @_;
29
    my ($self, $msg) = @_;
30
	my $conf = $self->{conf};
30
    my $conf = $self->{conf};
31
	my $logfile = $conf->{'logfile'};
31
    my $logfile = $conf->{'logfile'};
32
 
32
 
33
	open my $fh, ">>$logfile" or die "Can't write blat logfile $logfile: $!\n";
33
    open my $fh, ">>$logfile" or die "Can't write blat logfile $logfile: $!\n";
-
 
34
    $msg =~ s~\s+$~~;
34
	print $fh localtime()." (PID $$): $msg\n";
35
    print $fh localtime()." (PID $$): $msg\n";
35
    close $fh;
36
    close $fh;
36
 
37
 
37
    unless ( $self->{RollingLogs} )
38
    unless ( $self->{RollingLogs} )
38
    {
39
    {
39
        #
40
        #
Line 50... Line 51...
50
 
51
 
51
    return undef;
52
    return undef;
52
}
53
}
53
 
54
 
54
sub err ($$) {
55
sub err ($$) {
55
	my ($self, $msg) = @_;
56
    my ($self, $msg) = @_;
56
	$self->logmsg("ERROR: $msg");
57
    $self->logmsg("ERROR: $msg");
-
 
58
    $SIG{__WARN__} = undef;
57
    $SIG{__DIE__} = undef;
59
    $SIG{__DIE__} = undef;
58
	die "ERROR: $msg\n";
60
    die "ERROR: $msg\n";
59
}
61
}
60
 
62
 
61
sub warn ($$) {
63
sub warn ($$) {
62
	my ($self, $msg) = @_;
64
    my ($self, $msg) = @_;
63
	$self->logmsg("WARNING: $msg");
65
    $self->logmsg("WARNING: $msg");
64
    return undef;
66
    return undef;
65
}
67
}
66
 
68
 
67
sub verbose ($$) {
69
sub verbose ($$) {
68
    my $self = shift;
70
    my $self = shift;
69
	my $conf = $self->{conf};
71
    my $conf = $self->{conf};
70
	$self->logmsg("(V): @_") if ( $conf->{verbose} > 0 );
72
    $self->logmsg("(V): @_") if ( $conf->{verbose} > 0 );
71
    return undef;
73
    return undef;
72
}
74
}
73
 
75
 
74
sub verbose2 ($$) {
76
sub verbose2 ($$) {
75
    my $self = shift;
77
    my $self = shift;
76
	my $conf = $self->{conf};
78
    my $conf = $self->{conf};
77
	$self->logmsg("(V): @_") if ( $conf->{verbose} > 1 );
79
    $self->logmsg("(V): @_") if ( $conf->{verbose} > 1 );
78
    return undef;
80
    return undef;
79
}
81
}
80
 
82
 
81
sub verbose3 ($$) {
83
sub verbose3 ($$) {
82
    my $self = shift;
84
    my $self = shift;
83
	my $conf = $self->{conf};
85
    my $conf = $self->{conf};
84
	$self->logmsg("(V): @_") if ( $conf->{verbose} > 2 );
86
    $self->logmsg("(V): @_") if ( $conf->{verbose} > 2 );
85
    return undef;
87
    return undef;
86
}
88
}
87
 
89
 
88
 
90
 
89
sub rotatelog ($) {
91
sub rotatelog ($) {
90
	my $self = shift;
92
    my $self = shift;
91
	my $conf = $self->{conf};
93
    my $conf = $self->{conf};
92
	my $logfile = $conf->{'logfile'};
94
    my $logfile = $conf->{'logfile'};
93
    $self->{RollingLogs} = 1;
95
    $self->{RollingLogs} = 1;
94
 
96
 
95
	$self->logmsg('Rotating logfile');
97
    $self->logmsg('Rotating logfile');
96
    my $num = $conf->{'logfile.count'};
98
    my $num = $conf->{'logfile.count'};
97
    unlink "$logfile.$num" if ( -f "$logfile.$num");;
99
    unlink "$logfile.$num" if ( -f "$logfile.$num");;
98
    for (; $num > 1 ; $num--)
100
    for (; $num > 1 ; $num--)
99
    {
101
    {
100
        my $prev = $num - 1;
102
        my $prev = $num - 1;
101
        mv ("$logfile.$prev", "$logfile.$num") if ( -f "$logfile.$prev");
103
        mv ("$logfile.$prev", "$logfile.$num") if ( -f "$logfile.$prev");
102
    }
104
    }
103
    mv ($logfile, "$logfile.$num");
105
    mv ($logfile, "$logfile.$num");
104
	$self->logmsg('Rotating logfile complete');
106
    $self->logmsg('Rotating logfile complete');
105
    $self->{RollingLogs} = 0;
107
    $self->{RollingLogs} = 0;
106
    return undef;
108
    return undef;
107
}
109
}
108
 
110
 
109
1;
111
1;