| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HeliosX::Logger::HiRes; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20086
|
use 5.008; |
|
|
1
|
|
|
|
|
3
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
35
|
|
|
5
|
1
|
|
|
1
|
|
10
|
use warnings; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
41
|
|
|
6
|
1
|
|
|
1
|
|
1185
|
use parent 'Helios::Logger'; |
|
|
1
|
|
|
|
|
373
|
|
|
|
1
|
|
|
|
|
6
|
|
|
7
|
1
|
|
|
1
|
|
103182
|
use constant MAX_RETRIES => 3; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
62
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use constant RETRY_INTERVAL => 5; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
38
|
|
|
9
|
1
|
|
|
1
|
|
642
|
use Time::HiRes 'time'; |
|
|
1
|
|
|
|
|
1285
|
|
|
|
1
|
|
|
|
|
5
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
746
|
use Helios::LogEntry::Levels ':all'; |
|
|
1
|
|
|
|
|
371
|
|
|
|
1
|
|
|
|
|
153
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use Helios::Error::LoggingError; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
8
|
|
|
13
|
1
|
|
|
1
|
|
448
|
use HeliosX::Logger::HiRes::LogEntry; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
309
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
HeliosX::Logger::HiRes - enhanced, high-resolution logging for Helios applications |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# in a helios.ini file: |
|
24
|
|
|
|
|
|
|
[MyService] |
|
25
|
|
|
|
|
|
|
loggers=HeliosX::Logger::HiRes |
|
26
|
|
|
|
|
|
|
internal_logger=off |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
--OR-- |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# using helios_config_set |
|
31
|
|
|
|
|
|
|
helios_config_set -s MyService -H="*" -p loggers -v HeliosX::Logger::HiRes |
|
32
|
|
|
|
|
|
|
helios_config_set -s MyService -H="*" -p internal_logger -v off |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# then, use heliosx_logger_hires_search to search the log |
|
35
|
|
|
|
|
|
|
heliosx_logger_hires_search --service=MyService |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
HeliosX::Logger::HiRes is a Helios::Logger logging class that provides logging |
|
41
|
|
|
|
|
|
|
with high-resolution timestamp precision with a more normalized database |
|
42
|
|
|
|
|
|
|
structure. It also provides L, a command to |
|
43
|
|
|
|
|
|
|
view and search for log messages at the command line. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
HeliosX::Logger::HiRes must be added to your service using the B |
|
48
|
|
|
|
|
|
|
directive either using the B command or in B. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Additionally, as HeliosX::Logger::HiRes is largely intended to replace the |
|
51
|
|
|
|
|
|
|
Helios internal logger, once you are sure it is working properly in your |
|
52
|
|
|
|
|
|
|
installation you should turn off the Helios default logger using the |
|
53
|
|
|
|
|
|
|
B option. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
See the L page for complete information about the |
|
56
|
|
|
|
|
|
|
B and B directives. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
HeliosX::Logger::HiRes itself can be configured using the options below: |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=over 4 |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item * log_priority_threshold |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Unlike L and L, |
|
65
|
|
|
|
|
|
|
HeliosX::Logger::HiRes supports the Helios internal logger's |
|
66
|
|
|
|
|
|
|
B option to limit the messages actually being logged |
|
67
|
|
|
|
|
|
|
to a certain level. Unlike the others, HeliosX::Logger::HiRes is intended to |
|
68
|
|
|
|
|
|
|
replace rather than augment the Helios internal logger, so most users running |
|
69
|
|
|
|
|
|
|
HeliosX::Logger::HiRes will most likely turn off the Helios internal |
|
70
|
|
|
|
|
|
|
logger. Rather than create confusion with a separate threshold option, |
|
71
|
|
|
|
|
|
|
HeliosX::Logger::HiRes honors the internal logger's built-in |
|
72
|
|
|
|
|
|
|
B option. |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
The B value should be an integer matching one of the |
|
75
|
|
|
|
|
|
|
Helios logging priorities in L: |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Priority Name Integer Value |
|
78
|
|
|
|
|
|
|
LOG_EMERG 0 |
|
79
|
|
|
|
|
|
|
LOG_ALERT 1 |
|
80
|
|
|
|
|
|
|
LOG_CRIT 2 |
|
81
|
|
|
|
|
|
|
LOG_ERR 3 |
|
82
|
|
|
|
|
|
|
LOG_WARNING 4 |
|
83
|
|
|
|
|
|
|
LOG_NOTICE 5 |
|
84
|
|
|
|
|
|
|
LOG_INFO 6 |
|
85
|
|
|
|
|
|
|
LOG_DEBUG 7 |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Examples: |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# in helios.ini |
|
90
|
|
|
|
|
|
|
# for all services on this host, log everything but debug messages |
|
91
|
|
|
|
|
|
|
[global] |
|
92
|
|
|
|
|
|
|
log_priority_threshold=6 |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# at the command line, set all instances of MyService |
|
95
|
|
|
|
|
|
|
# to only log warnings and worse |
|
96
|
|
|
|
|
|
|
helios_config_set -s MyService -H="*" -p log_priority_threshold -v 4 |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=back |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 IMPLEMENTED METHODS |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 init() |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
HeliosX::Logger::HiRes->init() is empty. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
0
|
1
|
|
sub init { } |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 logMsg($job, $priority, $message) |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
The logMsg() method takes a job, priority, and log message and savesthe message |
|
113
|
|
|
|
|
|
|
to the high-resolution log table in the Helios collective database. |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
The job parameter should be a Helios::Job object. If the job value is |
|
116
|
|
|
|
|
|
|
undefined, no jobid is saved with the message. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
If the priority parameter is undefined, logMsg() defaults the message's |
|
119
|
|
|
|
|
|
|
priority to 6 (LOG_INFO). |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub logMsg { |
|
124
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
125
|
0
|
0
|
|
|
|
|
unless (scalar @_ == 3) { Helios::Error::LoggingError->throw(__PACKAGE__."->logMsg() ERROR: logMsg() requires 3 arguments: \$job, \$priority, \$message."); } |
|
|
0
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my ($job, $priority, $message) = @_; |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# deal with the log priority & threshold (if set) |
|
129
|
0
|
0
|
|
|
|
|
$priority = defined($priority) ? $priority : LOG_INFO; |
|
130
|
0
|
0
|
|
|
|
|
my $threshold = defined($self->getConfig()->{log_priority_threshold}) ? $self->getConfig()->{log_priority_threshold} : LOG_DEBUG; |
|
131
|
0
|
0
|
|
|
|
|
if ($priority > $threshold) { |
|
132
|
0
|
|
|
|
|
|
return 1; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my $success = 0; |
|
136
|
0
|
|
|
|
|
|
my $retries = 0; |
|
137
|
0
|
|
|
|
|
|
my $err; |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# deal with jobid & jobtypeid |
|
140
|
0
|
0
|
|
|
|
|
my $jobid = defined($job) ? $job->getJobid() : undef; |
|
141
|
0
|
0
|
|
|
|
|
my $jobtypeid = defined($job) ? $job->getJobtypeid() : undef; |
|
142
|
|
|
|
|
|
|
|
|
143
|
0
|
|
0
|
|
|
|
do { |
|
144
|
0
|
|
|
|
|
|
eval { |
|
145
|
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my $drvr = $self->getDriver(); |
|
147
|
0
|
|
|
|
|
|
my $obj = HeliosX::Logger::HiRes::LogEntry->new( |
|
148
|
|
|
|
|
|
|
log_time => sprintf("%.6f", time()), |
|
149
|
|
|
|
|
|
|
host => $self->getHostname(), |
|
150
|
|
|
|
|
|
|
pid => $$, |
|
151
|
|
|
|
|
|
|
jobid => $jobid, |
|
152
|
|
|
|
|
|
|
jobtypeid => $jobtypeid, |
|
153
|
|
|
|
|
|
|
service => $self->getService(), |
|
154
|
|
|
|
|
|
|
priority => $priority, |
|
155
|
|
|
|
|
|
|
message => $message, |
|
156
|
|
|
|
|
|
|
); |
|
157
|
0
|
|
|
|
|
|
$drvr->insert($obj); |
|
158
|
0
|
|
|
|
|
|
1; |
|
159
|
|
|
|
|
|
|
}; |
|
160
|
0
|
0
|
|
|
|
|
if ($@) { |
|
161
|
0
|
|
|
|
|
|
$err = $@; |
|
162
|
0
|
|
|
|
|
|
$retries++; |
|
163
|
0
|
|
|
|
|
|
sleep RETRY_INTERVAL; |
|
164
|
|
|
|
|
|
|
} else { |
|
165
|
|
|
|
|
|
|
# no exception? then declare success and move on |
|
166
|
0
|
|
|
|
|
|
$success = 1; |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
} until ($success || ($retries > MAX_RETRIES)); |
|
169
|
|
|
|
|
|
|
|
|
170
|
0
|
0
|
|
|
|
|
unless ($success) { |
|
171
|
0
|
|
|
|
|
|
Helios::Error::LoggingError->throw(__PACKAGE__."->logMsg() ERROR: $err"); |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
return 1; |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; |
|
178
|
|
|
|
|
|
|
__END__ |