Helios/Logger/Internal.pm

filter: Statementstmt 39.5% 19 / 48 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 6 / 8 Podpod 100% 2 / 2 totaltotal 38.0% 27 / 71 CC 6 SCAR 30.0
CC
6
Cov
32%
logMsg
42.0
init
2.0
BEGIN
1.0
CRAP 20.0
« Helios/TS/Job.pm ↑ Summary Helios/TestService.pm »
1 package Helios::Logger::Internal;
2  
3 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base qw(Helios::Logger);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Helios::LogEntry::Levels qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Helios::Error::LoggingError;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '2.61';
12  
13 # 2011-12-07: The code of Helios::Service->logMsg() was moved here to
14 # implement internal logging as a Helios::Logger subclass.
15 # 2012-01-02: Re-added support for log_priority_threshold config parameter.
16  
17 =head1 NAME
18  
19 Helios::Logger::Internal - Helios::Logger subclass implementing Helios internal logging
20  
21 =head1 SYNOPSIS
22  
23 #in helios.ini, enable internal Helios logging (this is default)
24 internal_logger=on
25
26 #in helios.ini, turn off internal logging
27 # make sure you've turned on another logger with the logger= directive
28 # otherwise you will have NO logging system active
29 internal_logger=off
30  
31  
32 =head1 DESCRIPTION
33  
34 Helios::Logger::Internal is a refactor of the logging functionality found in
35 the Helios 2.23 and earlier Helios::Service->logMsg(). This allows Helios
36 services to retain logging functionality found in the previous Helios core
37 system while also allowing Helios to be extended to support custom logging
38 solutions by subclassing Helios::Logger.
39  
40 =head1 IMPLEMENTED METHODS
41  
42 =head2 init()
43  
44 Helios::Logger::Internal->init() attempts to initialize the connection to the
45 Helios collective database so it will be available for later calls to logMsg().
46  
47 =cut
48  
49 0 ▶sub init {
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
50 0 my $self = shift;
51 0 $self->getDriver();
52 }
53  
54  
55 =head2 logMsg($job, $priority_level, $message)
56  
57 Implementation of the Helios::Service internal logging code refactored into a
58 Helios::Logger class.
59  
60 =cut
61  
62 0 ▶sub logMsg {
Subroutine logMsg: not called CC=6 SCAR=37.4
Pod documented
63 0 my $self = shift;
64 0 my $job = shift;
65 0 my $level = shift;
66 0 my $msg = shift;
67  
68 0 my $params = $self->getConfig();
69 0 my $jobType = $self->getJobType();
70 0 my $hostname = $self->getHostname();
71  
72 # 2012-01-02: Re-added support for log_priority_threshold config parameter.
73 # if this log message's priority is lower than log_priority_threshold,
74 # don't bother logging the message
75 0 ▶ if ( defined($params->{log_priority_threshold}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params->{"log_priority_threshold"} and $level > $params->{"log_priority_threshold"}) 0 0 0
Condition0%0/3
defined $params->{"log_priority_threshold"} and $level > $params->{"log_priority_threshold"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $params->{"log_priority_threshold"} and $level > $params->{"log_priority_threshold"}
defined $params->{"log_priority_threshold"} $level > $params->{"log_priority_threshold"}
Truth table0%0/3
A and B
A= defined $params->{"log_priority_threshold"}B= $level > $params->{"log_priority_threshold"}
ABresult
0X0
100
111
76 $level > $params->{log_priority_threshold} ) {
77 0 return 1;
78 }
79 # END 2012-01-02 modification.
80  
81 0 my $retries = 0;
82 0 my $retry_limit = 3;
83 RETRY: {
84 0 eval {
85 0 my $driver = $self->getDriver();
86 0 my $log_entry;
87 0 ▶ if ( defined($job) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $job) { } 0 0 0
88 0 $log_entry = Helios::LogEntry->new(
89 log_time => time(),
90 host => $self->getHostname(),
91 process_id => $$,
92 jobid => $job->getJobid(),
93 funcid => $job->getFuncid(),
94 job_class => $jobType,
95 priority => $level,
96 message => $msg
97 );
98 } else {
99 0 $log_entry = Helios::LogEntry->new(
100 log_time => time(),
101 host => $self->getHostname(),
102 process_id => $$,
103 jobid => undef,
104 funcid => undef,
105 job_class => $jobType,
106 priority => $level,
107 message => $msg
108 );
109 }
110 0 $driver->insert($log_entry);
111 0 1;
112 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { my $driver = $self->getDriver; my $log_entry; if (defined $job) { $log_entry = "Helios::LogEntry"->new("log_time", time, "host", $self->getHostname, "process_id", $$, "jobid", $job->getJobid, "funcid", $job->getFuncid, "job_class", $jobType, "priority", $level, "message", $msg); } else { $log_entry = "Helios::LogEntry"->new("log_time", time, "host", $self->getHostname, "process_id", $$, "jobid", undef, "funcid", undef, "job_class", $jobType, "priority", $level, "message", $msg); } ; $driver->insert($log_entry); 1 } } or do { my $E = $@; if ($retries > $retry_limit) { "Helios::Error::LoggingError"->throw("$E"); } else { ++$retries; sleep 5; next RETRY; } } 0 0 0
113 0 my $E = $@;
114 0 ▶ if ($retries > $retry_limit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retries > $retry_limit) { } 0 0 0
115 0 Helios::Error::LoggingError->throw("$E");
116 } else {
117 # we're going to give it another shot
118 0 $retries++;
119 0 sleep 5;
120 0 next RETRY;
121 }
122 };
123 }
124 # retry block end
125 0 return 1;
126 }
127  
128  
129 1 1;
130 __END__
« Helios/TS/Job.pm ↑ Summary Helios/TestService.pm »