| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Net::MSN::Debug - standardised logging routine. |
|
2
|
|
|
|
|
|
|
# Written by DJ |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# $Id: Debug.pm,v 1.2 2003/07/02 14:14:55 david Exp $ |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Net::MSN::Debug; |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
33
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
37
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
BEGIN { |
|
12
|
1
|
|
|
1
|
|
5
|
use Fcntl 'O_RDWR', 'O_CREAT'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
72
|
|
|
13
|
1
|
|
|
1
|
|
744
|
use POSIX; |
|
|
1
|
|
|
|
|
7925
|
|
|
|
1
|
|
|
|
|
10
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
3677
|
use vars qw($VERSION); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
121
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
3
|
$VERSION = do { my @r=(q$Revision: 1.2 $=~/\d+/g); sprintf "%d."."%03d"x$#r,@r }; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
806
|
|
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# my $Logger = new Net::MSN::Debug(%opts); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
|
23
|
0
|
|
|
0
|
0
|
|
my ($class, %args) = @_; |
|
24
|
|
|
|
|
|
|
|
|
25
|
0
|
|
0
|
|
|
|
my $self = bless({ |
|
26
|
|
|
|
|
|
|
'Debug' => 0, |
|
27
|
|
|
|
|
|
|
'Level' => 0, |
|
28
|
|
|
|
|
|
|
'LogFile' => '', |
|
29
|
|
|
|
|
|
|
'STDERR' => 0, |
|
30
|
|
|
|
|
|
|
'STDOUT' => 0, |
|
31
|
|
|
|
|
|
|
'LogCaller' => 1, |
|
32
|
|
|
|
|
|
|
'LogTime' => 1, |
|
33
|
|
|
|
|
|
|
'LogLevel' => 1, |
|
34
|
|
|
|
|
|
|
'Version' => $VERSION |
|
35
|
|
|
|
|
|
|
}, ref($class) || $class); |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$self->_set_options(\%args); |
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
|
|
0
|
|
|
$self->{log_obj} = sub{ $self->log(@_) }; |
|
|
0
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
return $self; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _set_options { |
|
45
|
0
|
|
|
0
|
|
|
my ($self, $opts) = @_; |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my %opts = %$opts; |
|
48
|
0
|
|
|
|
|
|
foreach my $key (keys %opts) { |
|
49
|
0
|
|
|
|
|
|
$self->{$key} = $opts{$key}; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub get_log_obj { |
|
54
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
return $self->{log_obj}; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub clean { |
|
60
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
0
|
0
|
|
|
|
if (defined $self->{LogFile} && -f $self->{LogFile}) { |
|
63
|
0
|
|
|
|
|
|
unlink($self->{LogFile}); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub log { |
|
68
|
0
|
|
|
0
|
0
|
|
my ($self, $msg, $lvl, $file) = @_; |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
0
|
0
|
|
|
|
$lvl = 1 unless (defined $lvl && $lvl); |
|
71
|
0
|
0
|
|
|
|
|
$self->{Level} = 1 unless (defined $self->{Level}); |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
0
|
0
|
|
|
|
return unless ((defined $self->{Debug} && $self->{Debug} == 1) && |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
74
|
|
|
|
|
|
|
(defined $self->{Level} && $self->{Level} !=0 && |
|
75
|
|
|
|
|
|
|
$self->{Level} >= $lvl)); |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $logentry; |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
0
|
0
|
|
|
|
if (defined $self->{LogTime} && $self->{LogTime} == 1) { |
|
80
|
0
|
|
|
|
|
|
my $date = POSIX::strftime( "%H:%M:%S %d %b %Y", localtime(time) ); |
|
81
|
0
|
|
|
|
|
|
$logentry .= $date. ': '; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
0
|
0
|
|
|
|
if (defined $self->{LogCaller} && $self->{LogCaller} == 1) { |
|
85
|
0
|
|
|
|
|
|
my ($package, $filename, $lineno, $subroutine, $hasargs, $wantarray, |
|
86
|
|
|
|
|
|
|
$evaltext, $is_require, $hints, $bitmask) = caller(1); |
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
0
|
0
|
|
|
|
unless (defined $subroutine && defined $package) { |
|
|
|
0
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
($package, $filename, $lineno, $subroutine, $hasargs, $wantarray, |
|
90
|
|
|
|
|
|
|
$evaltext, $is_require, $hints, $bitmask) = caller(); |
|
91
|
|
|
|
|
|
|
} elsif ($subroutine eq __PACKAGE__. '::__ANON__') { |
|
92
|
0
|
|
|
|
|
|
($package, $filename, $lineno, $subroutine, $hasargs, $wantarray, |
|
93
|
|
|
|
|
|
|
$evaltext, $is_require, $hints, $bitmask) = caller(2); |
|
94
|
|
|
|
|
|
|
} |
|
95
|
0
|
0
|
0
|
|
|
|
$subroutine = $package. ' '. $subroutine. ' line: '. $lineno |
|
96
|
|
|
|
|
|
|
if (defined $subroutine && $subroutine =~ /^[(]*eval[)]*$/); |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
0
|
0
|
|
|
|
$logentry .= (defined $subroutine && $subroutine) ? $subroutine : 'main'; |
|
99
|
0
|
|
|
|
|
|
$logentry .= ' '; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
0
|
0
|
0
|
|
|
|
if (defined $self->{LogLevel} && $self->{LogLevel} == 1) { |
|
103
|
0
|
|
|
|
|
|
$logentry .= 'L'. $lvl; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
0
|
0
|
0
|
|
|
|
$logentry .= (defined $logentry && $logentry) ? '> '. $msg : $msg; |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
0
|
0
|
|
|
|
if (defined $self->{LogFile} && $self->{LogFile}) { |
|
109
|
0
|
|
|
|
|
|
open(DEBUGLOG, '>>'. $self->{LogFile}); |
|
110
|
0
|
|
|
|
|
|
print DEBUGLOG $logentry. "\n"; |
|
111
|
0
|
|
|
|
|
|
close(DEBUGLOG); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
0
|
0
|
0
|
|
|
|
if (defined $self->{STDERR} && $self->{STDERR} == 1) { |
|
|
|
0
|
0
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
print STDERR $logentry. "\n"; |
|
115
|
|
|
|
|
|
|
} elsif (defined $self->{STDOUT} && $self->{STDOUT} == 1) { |
|
116
|
0
|
|
|
|
|
|
print STDOUT $logentry. "\n"; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
|
121
|
|
|
|
|
|
|
|