Helios/Logger.pm

filter: Statementstmt 59.4% 44 / 74 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 48.1% 13 / 27 Podpod 14.2% 2 / 14 totaltotal 48.7% 59 / 121 CC 4 SCAR 9.6
CC
4
Cov
55%
initDriver
12.0
debug
6.0
setService
2.0
CRAP 2.6
« Helios/MetajobBurstService.pm ↑ Summary Bundle/Helios.pm »
1 package Helios::Logger;
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  
7 1 ▶use Helios::Job;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Helios::Error::LoggingError;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Helios::ObjectDriver::DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '2.81';
12  
13 =head1 NAME
14  
15 Helios::Logger - Base class for sending Helios logging information to external loggers
16  
17 =head1 SYNOPSIS
18  
19 # in your logging system shim class
20 use strict;
21 use warnings;
22 use base qw(Helios::Logger);
23 # optional, but probably useful
24 use Helios::LogEntry::Levels qw(:all);
25 use Helios::Error::LoggingError;
26
27 sub init {
28 my $self = shift;
29  
30 ...initialization code for your logging system...
31 }
32
33 sub logMsg {
34 my $self = shift;
35 my $job = shift;
36 my $priority_level = shift;
37 my $log_message = shift;
38 ...code to log the message to your logging system...
39 }
40  
41  
42 =head1 DESCRIPTION
43  
44 Helios::Logger is the base class to extend to provide interfaces to external
45 logging systems for Helios services. It provides a basic set of accessor
46 methods to get and store information about the Helios environment, and defines
47 interface methods for you to override in your class to actually implement the
48 logging code.
49  
50 It should be noted that all methods are actually class methods, not instance
51 (object) methods, because Helios::Logger subclasses are not instantiated. If
52 you need to implement other methods outside of the interface methods defined
53 below, make sure you implement them as class methods.
54  
55 =head1 ACCESSOR METHODS
56  
57 Helios::Logger provides 4 set/get accessor pairs to provide access to
58 information from the Helios collective environment:
59  
60 set/getConfig(); # config hashref from Helios::Service->getConfig()
61 set/getJobType(); # job type/service name string from Helios::Service->getJobType()
62 set/getHostname(); # host job is running on from Helios::Service->getHostname()
63 set/getDriver(); # Data::ObjectDriver object connected to Helios collective
64 database from Helios::Service->getDriver()
65
66 Normally, Helios::Service->logMsg() calls the set* methods before the init()
67 method to properly initialize the logging class. If these values can be
68 adjusted in the init() method if necessary.
69  
70 =cut
71  
72 1 my $Config;
73 my $JobType;
74 1 my $Hostname;
75 1 my $Driver;
76 1 my $Debug;
77  
78 0 ▶sub debug { my $self = shift; @_ ? $Debug = shift : $Debug; }
Subroutine debug: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
79  
80 0 ▶sub setConfig {
Subroutine setConfig: not called CC=1 SCAR=0.6
Pod undocumented
81 0 my $var = $_[0]."::Config";
82 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
83 0 $$var = $_[1];
84 }
85 0 ▶sub getConfig {
Subroutine getConfig: not called CC=1 SCAR=0.6
Pod undocumented
86 0 my $var = $_[0]."::Config";
87 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
88 0 return $$var;
89 }
90  
91 0 ▶sub setJobType {
Subroutine setJobType: not called CC=1 SCAR=0.6
Pod undocumented
92 0 my $var = $_[0]."::JobType";
93 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
94 0 $$var = $_[1];
95 }
96 0 ▶sub getJobType {
Subroutine getJobType: not called CC=1 SCAR=0.6
Pod undocumented
97 0 my $var = $_[0]."::JobType";
98 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
99 0 return $$var;
100 }
101  
102 # BEGIN CODE Copyright (C) 2014 by Logical Helion, LLC.
103 0 ▶sub setService {
Subroutine setService: not called CC=1 SCAR=6.9
Pod undocumented
104 0 setJobType(@_);
105 }
106 0 ▶sub getService {
Subroutine getService: not called CC=1 SCAR=6.9
Pod undocumented
107 0 getJobType(@_);
108 }
109 # END CODE Copyright (C) 2014 by Logical Helion, LLC.
110  
111  
112 0 ▶sub setHostname {
Subroutine setHostname: not called CC=1 SCAR=0.6
Pod undocumented
113 0 my $var = $_[0]."::Hostname";
114 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
115 0 $$var = $_[1];
116 }
117 0 ▶sub getHostname {
Subroutine getHostname: not called CC=1 SCAR=0.6
Pod undocumented
118 0 my $var = $_[0]."::Hostname";
119 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
120 0 return $$var;
121 }
122  
123 0 ▶sub setDriver {
Subroutine setDriver: not called CC=1 SCAR=0.6
Pod undocumented
124 0 my $var = $_[0]."::Driver";
125 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
126 0 $$var = $_[1];
127 }
128 0 ▶sub getDriver {
Subroutine getDriver: not called CC=1 SCAR=6.9
Pod undocumented
129 0 return initDriver(@_);
130 }
131 0 ▶sub initDriver {
Subroutine initDriver: not called CC=3 SCAR=24.8
Pod undocumented
132 0 my $self = shift;
133 0 my $config = $self->getConfig();
134 0 ▶ if ($self->debug) { print $config->{dsn},$config->{user},$config->{password},"\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) 0 0 0
135 my $driver = Helios::ObjectDriver::DBI->new(
136 dsn => $config->{dsn},
137 username => $config->{user},
138 password => $config->{password}
139 0 );
140 0 ▶ if ($self->debug) { print 'Logger->initDriver() DRIVER: ',$driver,"\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) 0 0 0
141 0 $self->setDriver($driver);
142 0 return $driver;
143 }
144  
145  
146 =head1 INTERFACE METHODS
147  
148 The following methods must be implemented by your Helios::Logger subclass for
149 external logging to work.
150  
151 =head2 init()
152  
153 Class method to initialize the logging code for the external logging system.
154 This will be run once when the service daemon starts. You also can use init()
155 to check for configuration errors or adjust configuration parameters
156 (set/getConfig()). If your logging system doesn't need any
157 initialization, go ahead and declare an empty init() method in your class
158 anyway.
159  
160 =cut
161  
162 0 ▶sub init {
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
163 0 throw Helios::Error::LoggingError('init() not defined for '. __PACKAGE__);
164 }
165  
166  
167 =head2 logMsg($job, $priority_level, $message)
168  
169 Class method to send the message to the external logging system for logging.
170 The $job parameter is a Helios::Job object, while $priority_level is an integer
171 corresponding to one of the symbols defined in Helios::LogEntry::Levels (which
172 are the same as Sys::Syslog's). The implementation of this method in your
173 subclass should use the external logging system to log these values
174 appropriately. It should throw a Helios::Error::LoggingError if it encounters
175 an error.
176  
177 NOTE: When Helios::Service->logMsg() calls this method, it is guaranteed to
178 have three values, so when implementing this method in your subclass you don't
179 have to worry about parameter parsing as much as the calling routine does.
180 However, the values of $job and/or $priority_level may be undefined values, and
181 your implementation of logMsg() will have to deal with that appropriately.
182  
183 =cut
184  
185 0 ▶sub logMsg {
Subroutine logMsg: not called CC=1 SCAR=6.9
Pod documented
186 0 throw Helios::Error::LoggingError('logMsg() not defined for '. __PACKAGE__);
187 }
188  
189  
190 1 1;
191 __END__
« Helios/MetajobBurstService.pm ↑ Summary Bundle/Helios.pm »