| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Monitoring::TT::Log; |
|
2
|
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
30
|
use strict; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
116
|
|
|
4
|
5
|
|
|
5
|
|
22
|
use warnings; |
|
|
5
|
|
|
|
|
6
|
|
|
|
5
|
|
|
|
|
170
|
|
|
5
|
5
|
|
|
5
|
|
21
|
use utf8; |
|
|
5
|
|
|
|
|
8
|
|
|
|
5
|
|
|
|
|
18
|
|
|
6
|
5
|
|
|
5
|
|
85
|
use Data::Dumper; |
|
|
5
|
|
|
|
|
6
|
|
|
|
5
|
|
|
|
|
756
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$Monitoring::TT::Log::Verbose = 1; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw(error warn info debug trace log); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
BEGIN { |
|
15
|
|
|
|
|
|
|
# check if we have ansi color support |
|
16
|
5
|
|
|
5
|
|
16
|
$Monitoring::TT::Log::has_ansi = 0; |
|
17
|
5
|
|
|
|
|
8
|
eval { |
|
18
|
5
|
|
|
|
|
2620
|
require Term::ANSIColor; |
|
19
|
5
|
|
|
|
|
37407
|
Term::ANSIColor->import(); |
|
20
|
|
|
|
|
|
|
}; |
|
21
|
5
|
50
|
|
|
|
25
|
$Monitoring::TT::Log::has_ansi = 1 unless $@; |
|
22
|
5
|
50
|
33
|
|
|
2626
|
$Monitoring::TT::Log::has_ansi = 0 unless(-t STDIN && -t STDOUT); |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
##################################################################### |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 NAME |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Monitoring::TT::Log - Loging Facility |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Generates output to STDOUT and STDERR |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 METHODS |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 error |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
write a error message to stderr |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
|
42
|
|
|
|
|
|
|
sub error { |
|
43
|
0
|
0
|
|
0
|
1
|
0
|
print STDERR color('red') if $Monitoring::TT::Log::Verbose >= 0; |
|
44
|
0
|
0
|
|
|
|
0
|
_out($_[0],'error') if $Monitoring::TT::Log::Verbose >= 0; |
|
45
|
0
|
0
|
|
|
|
0
|
print STDERR color('reset') if $Monitoring::TT::Log::Verbose >= 0; |
|
46
|
0
|
|
|
|
|
0
|
return ""; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
##################################################################### |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 warn |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
write a warning message to stderr |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
|
56
|
|
|
|
|
|
|
sub warn { |
|
57
|
0
|
0
|
|
0
|
1
|
0
|
print STDERR color('yellow') if $Monitoring::TT::Log::Verbose >= 1; |
|
58
|
0
|
0
|
|
|
|
0
|
_out($_[0],'warning') if $Monitoring::TT::Log::Verbose >= 1; |
|
59
|
0
|
0
|
|
|
|
0
|
print STDERR color('reset') if $Monitoring::TT::Log::Verbose >= 1; |
|
60
|
0
|
|
|
|
|
0
|
return ""; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
##################################################################### |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 info |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
write a info message to stdout |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
|
70
|
|
|
|
|
|
|
sub info { |
|
71
|
5
|
50
|
|
5
|
1
|
18
|
_out($_[0],'info') if $Monitoring::TT::Log::Verbose >= 2; |
|
72
|
5
|
|
|
|
|
10
|
return ""; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
##################################################################### |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 debug |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
write a debug message to stdout |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
|
82
|
|
|
|
|
|
|
sub debug { |
|
83
|
9
|
50
|
|
9
|
1
|
34
|
_out($_[0],'debug') if $Monitoring::TT::Log::Verbose >= 3; |
|
84
|
9
|
|
|
|
|
23
|
return ""; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
##################################################################### |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 trace |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
write a trace message to stdout |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
|
94
|
|
|
|
|
|
|
sub trace { |
|
95
|
4
|
50
|
|
4
|
1
|
12
|
_out($_[0],'trace') if $Monitoring::TT::Log::Verbose >= 4; |
|
96
|
4
|
|
|
|
|
7
|
return ""; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
##################################################################### |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 log |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
log something, if line starts with ERROR: its an error, info otherwise |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
|
106
|
|
|
|
|
|
|
sub log { |
|
107
|
0
|
|
|
0
|
1
|
|
my($msg) = @_; |
|
108
|
0
|
0
|
|
|
|
|
if(ref $msg) { |
|
109
|
0
|
|
|
|
|
|
info($msg); |
|
110
|
0
|
|
|
|
|
|
return ""; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
0
|
0
|
|
|
|
|
if($msg =~ m/^ERROR:/mx) { |
|
|
|
0
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
$msg =~ s/^ERROR:\s*//gmx; |
|
114
|
0
|
|
|
|
|
|
error($msg); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
elsif($msg =~ m/^WARNING:/mx) { |
|
117
|
0
|
|
|
|
|
|
$msg =~ s/^WARNING:\s*//gmx; |
|
118
|
0
|
|
|
|
|
|
&warn($msg); |
|
119
|
|
|
|
|
|
|
} else { |
|
120
|
0
|
|
|
|
|
|
_out($msg, 'plain'); |
|
121
|
|
|
|
|
|
|
} |
|
122
|
0
|
|
|
|
|
|
return ""; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
##################################################################### |
|
126
|
|
|
|
|
|
|
sub _out { |
|
127
|
0
|
|
|
0
|
|
|
my($data, $lvl, $time) = @_; |
|
128
|
0
|
0
|
|
|
|
|
return "" unless defined $data; |
|
129
|
0
|
|
0
|
|
|
|
$time = $time || (scalar localtime()); |
|
130
|
0
|
0
|
|
|
|
|
if(ref $data) { |
|
131
|
0
|
|
|
|
|
|
return _out(Dumper($data), $lvl, $time); |
|
132
|
|
|
|
|
|
|
} |
|
133
|
0
|
|
|
|
|
|
for my $line (split/\n/mx, $data) { |
|
134
|
0
|
0
|
|
|
|
|
if($lvl eq 'plain') { |
|
135
|
0
|
|
|
|
|
|
print $line, "\n"; |
|
136
|
0
|
|
|
|
|
|
next; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
0
|
|
|
|
|
|
my $txt = "[".$time."][".uc($lvl)."] ".$line."\n"; |
|
139
|
0
|
0
|
0
|
|
|
|
if($lvl eq 'error' or $lvl eq 'warning') { |
|
140
|
0
|
|
|
|
|
|
print STDERR $txt; |
|
141
|
|
|
|
|
|
|
} else { |
|
142
|
0
|
|
|
|
|
|
print STDOUT $txt; |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
} |
|
145
|
0
|
|
|
|
|
|
return ""; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
##################################################################### |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 AUTHOR |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Sven Nierlein, 2013, |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
1; |