File Coverage

blib/lib/Helios/Logger/Internal.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             package Helios::Logger::Internal;
2              
3 1     1   1498 use 5.008;
  1         3  
  1         31  
4 1     1   3 use base qw(Helios::Logger);
  1         2  
  1         82  
5             use strict;
6             use warnings;
7              
8             use Helios::LogEntry::Levels qw(:all);
9             use Helios::Error::LoggingError;
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             my $self = shift;
51             $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             my $self = shift;
64             my $job = shift;
65             my $level = shift;
66             my $msg = shift;
67              
68             my $params = $self->getConfig();
69             my $jobType = $self->getJobType();
70             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             if ( defined($params->{log_priority_threshold}) &&
76             $level > $params->{log_priority_threshold} ) {
77             return 1;
78             }
79             # END 2012-01-02 modification.
80              
81             my $retries = 0;
82             my $retry_limit = 3;
83             RETRY: {
84             eval {
85             my $driver = $self->getDriver();
86             my $log_entry;
87             if ( defined($job) ) {
88             $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             $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             $driver->insert($log_entry);
111             1;
112             } or do {
113             my $E = $@;
114             if ($retries > $retry_limit) {
115             Helios::Error::LoggingError->throw("$E");
116             } else {
117             # we're going to give it another shot
118             $retries++;
119             sleep 5;
120             next RETRY;
121             }
122             };
123             }
124             # retry block end
125             return 1;
126             }
127              
128              
129             1;
130             __END__