| 1 | package HeliosX::Logger::HiRes; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use parent 'Helios::Logger'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use constant MAX_RETRIES => 3; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use constant RETRY_INTERVAL => 5; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Time::HiRes 'time'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Helios::LogEntry::Levels ':all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Helios::Error::LoggingError; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use HeliosX::Logger::HiRes::LogEntry; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | our $VERSION = '0.10_3270'; | |||||||||||||||||||||||||||
| 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<heliosx_logger_hires_search>, 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<loggers> | ||||||||||||||||||||||||||||
| 48 | directive either using the B<helios_config_set> command or in B<helios.ini>. | ||||||||||||||||||||||||||||
| 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<internal_logger=off> option. | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | See the L<Helios::Configuration> page for complete information about the | ||||||||||||||||||||||||||||
| 56 | B<loggers> and B<internal_logger> 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<HeliosX::Logger::Syslog> and L<HeliosX::Logger::Log4perl>, | ||||||||||||||||||||||||||||
| 65 | HeliosX::Logger::HiRes supports the Helios internal logger's | ||||||||||||||||||||||||||||
| 66 | B<log_priority_threshold> 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<log_priority_threshold> option. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | The B<log_priority_threshold> value should be an integer matching one of the | ||||||||||||||||||||||||||||
| 75 | Helios logging priorities in L<Helios::LogEntry::Levels>: | ||||||||||||||||||||||||||||
| 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 | ▶ | sub init { } | |||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 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 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
logMsg: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | unless (scalar @_ == 3) { Helios::Error::LoggingError->throw(__PACKAGE__."->logMsg() ERROR: logMsg() requires 3 arguments: \$job, \$priority, \$message."); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | my ($job, $priority, $message) = @_; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | # deal with the log priority & threshold (if set) | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | $priority = defined($priority) ? $priority : LOG_INFO; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | my $threshold = defined($self->getConfig()->{log_priority_threshold}) ? $self->getConfig()->{log_priority_threshold} : LOG_DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if ($priority > $threshold) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | my $jobid = defined($job) ? $job->getJobid() : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | my $jobtypeid = defined($job) ? $job->getJobtypeid() : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$success or $retries > 3
MC/DC0%0/2
$success or $retries > 3
$success
$retries > 3
Truth table0%0/3
A or B
A= $successB= $retries > 3
| |||||||||||||||||||||||||||||
| 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 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | unless ($success) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 0 | Helios::Error::LoggingError->throw(__PACKAGE__."->logMsg() ERROR: $err"); | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | return 1; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 1 | 1; | |||||||||||||||||||||||||||
| 178 | __END__ | ||||||||||||||||||||||||||||