File Coverage

blib/lib/Helios/Logger/Internal.pm
Criterion Covered Total %
statement 17 46 36.9
branch 0 8 0.0
condition 0 3 0.0
subroutine 6 8 75.0
pod 2 2 100.0
total 25 67 37.3


line stmt bran cond sub pod time code
1             package Helios::Logger::Internal;
2              
3 1     1   761 use 5.008;
  1         2  
4 1     1   4 use base qw(Helios::Logger);
  1         2  
  1         74  
5 1     1   5 use strict;
  1         1  
  1         17  
6 1     1   3 use warnings;
  1         1  
  1         29  
7              
8 1     1   3 use Helios::LogEntry::Levels qw(:all);
  1         1  
  1         145  
9 1     1   4 use Helios::Error::LoggingError;
  1         3  
  1         5  
10              
11             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             sub init {
50 0     0 1   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             sub logMsg {
63 0     0 1   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 0 0       if ( defined($params->{log_priority_threshold}) &&
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 0         if ( defined($job) ) {
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 0         } or do {
113 0           my $E = $@;
114 0 0         if ($retries > $retry_limit) {
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;
130             __END__