| 1 | # Copyright 2011, Google Inc. All Rights Reserved. | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||
| 4 | # you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||
| 5 | # You may obtain a copy of the License at | ||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | # Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||
| 12 | # See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||
| 13 | # limitations under the License. | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | package Google::Ads::AdWords::Logging; | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # The following needs to be on one line because CPAN uses a particularly hacky | ||||||||||||||||||||||||||||
| 22 | # eval() to determine module versions. | ||||||||||||||||||||||||||||
| 23 | 3 | ▶ | use Google::Ads::AdWords::Constants; our $VERSION = ${Google::Ads::AdWords::Constants::VERSION}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 3 | ▶ | use File::HomeDir; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 3 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 3 | ▶ | use Log::Log4perl qw(get_logger :levels); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # Module initialization. | ||||||||||||||||||||||||||||
| 30 | # This the log4perl configration format. | ||||||||||||||||||||||||||||
| 31 | 1 | my $logs_folder = File::Spec->catfile(File::HomeDir->my_home, "logs"); | |||||||||||||||||||||||||||
| 32 | 1 | my $awapi_log_file = File::Spec->catfile($logs_folder, "aw_api_lib.log"); | |||||||||||||||||||||||||||
| 33 | 1 | my $soap_log_file = File::Spec->catfile($logs_folder, "soap_xml.log"); | |||||||||||||||||||||||||||
| 34 | 1 | my $default_conf = <<TEXT; | |||||||||||||||||||||||||||
| 35 | log4perl.category.Google.Ads.AdWords.AWAPI = INFO, LogAWfile | ||||||||||||||||||||||||||||
| 36 | log4perl.appender.LogAWfile = Log::Log4perl::Appender::File | ||||||||||||||||||||||||||||
| 37 | log4perl.appender.LogAWfile.filename = ${awapi_log_file} | ||||||||||||||||||||||||||||
| 38 | log4perl.appender.LogAWfile.create_at_logtime = 1 | ||||||||||||||||||||||||||||
| 39 | log4perl.appender.LogAWfile.layout = Log::Log4perl::Layout::PatternLayout | ||||||||||||||||||||||||||||
| 40 | log4perl.appender.LogAWfile.layout.ConversionPattern = [%d{DATE} - %-5p] %m%n | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | log4perl.category.Google.Ads.AdWords.SOAP_XML = INFO, LogSOAPfile | ||||||||||||||||||||||||||||
| 43 | log4perl.appender.LogSOAPfile = Log::Log4perl::Appender::File | ||||||||||||||||||||||||||||
| 44 | log4perl.appender.LogSOAPfile.filename = ${soap_log_file} | ||||||||||||||||||||||||||||
| 45 | log4perl.appender.LogSOAPfile.create_at_logtime = 1 | ||||||||||||||||||||||||||||
| 46 | log4perl.appender.LogSOAPfile.layout = Log::Log4perl::Layout::PatternLayout | ||||||||||||||||||||||||||||
| 47 | log4perl.appender.LogSOAPfile.layout.ConversionPattern = [%d{DATE} - %-5p] %m%n | ||||||||||||||||||||||||||||
| 48 | TEXT | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # Static module-level variables. | ||||||||||||||||||||||||||||
| 51 | 1 | my ($awapi_logger, $soap_logger); | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # Initializes Log4Perl infrastructure | ||||||||||||||||||||||||||||
| 54 | 17 | ▶ | sub initialize_logging { | ||||||||||||||||||||||||||
|
Subroutine
initialize_logging: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | # Only initialize once | ||||||||||||||||||||||||||||
| 56 | 17 | ▶ | unless (Log::Log4perl->initialized()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | # Trying to read from the log4perl.conf file if not configuring the | ||||||||||||||||||||||||||||
| 58 | # defaults. | ||||||||||||||||||||||||||||
| 59 | 1 | my $log4perl_conf = | |||||||||||||||||||||||||||
| 60 | File::Spec->catfile(File::HomeDir->my_home, "log4perl.conf"); | ||||||||||||||||||||||||||||
| 61 | 1 | ▶ | if (-r $log4perl_conf) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | Log::Log4perl->init($log4perl_conf); | |||||||||||||||||||||||||||
| 63 | } else { | ||||||||||||||||||||||||||||
| 64 | 1 | ▶ | mkdir ${logs_folder} unless -d ${logs_folder}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 1 | Log::Log4perl->init(\$default_conf); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # Log4Perl may be initialized by another package; check that our loggers are | ||||||||||||||||||||||||||||
| 70 | # set up | ||||||||||||||||||||||||||||
| 71 | 17 | ▶ | unless ($awapi_logger and $soap_logger) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$awapi_logger and $soap_logger
MC/DC50%1/2
$awapi_logger and $soap_logger
$awapi_logger
$soap_logger
Truth table66%2/3
A and B
A= $awapi_loggerB= $soap_logger
| |||||||||||||||||||||||||||||
| 72 | 1 | $awapi_logger = get_logger("Google::Ads::AdWords::AWAPI"); | |||||||||||||||||||||||||||
| 73 | 1 | $soap_logger = get_logger("Google::Ads::AdWords::SOAP_XML"); | |||||||||||||||||||||||||||
| 74 | 1 | $awapi_logger->level($OFF); | |||||||||||||||||||||||||||
| 75 | 1 | $soap_logger->level($OFF); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # Enables the logging of the AdWords API takes one boolean | ||||||||||||||||||||||||||||
| 80 | # parameter, if true enables the logging in debug (more verbose) mode. | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub enable_awapi_logging { | ||||||||||||||||||||||||||
|
Subroutine
enable_awapi_logging: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 0 | initialize_logging(); | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($_[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | $awapi_logger->level($DEBUG); | |||||||||||||||||||||||||||
| 85 | } else { | ||||||||||||||||||||||||||||
| 86 | 0 | $awapi_logger->level($INFO); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # Disables all AdWords API logging. | ||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub disable_awapi_logging { | ||||||||||||||||||||||||||
|
Subroutine
disable_awapi_logging: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 0 | $awapi_logger->level($OFF); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # Enables the logging of the SOAP Traffic (request and responses). | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub enable_soap_logging { | ||||||||||||||||||||||||||
|
Subroutine
enable_soap_logging: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 0 | initialize_logging(); | |||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ($_[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | $soap_logger->level($DEBUG); | |||||||||||||||||||||||||||
| 100 | } else { | ||||||||||||||||||||||||||||
| 101 | 0 | $soap_logger->level($INFO); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # Disables all SOAP Traffic logging. | ||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub disable_soap_logging { | ||||||||||||||||||||||||||
|
Subroutine
disable_soap_logging: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 0 | $soap_logger->level($OFF); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | # Enables all logging which includes SOAP Traffic logging and API Errors | ||||||||||||||||||||||||||||
| 111 | # logging. | ||||||||||||||||||||||||||||
| 112 | 1 | ▶ | sub enable_all_logging { | ||||||||||||||||||||||||||
|
Subroutine
enable_all_logging: called CC=2 SCAR=7.9
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 1 | initialize_logging(); | |||||||||||||||||||||||||||
| 114 | 1 | ▶ | if ($_[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | $awapi_logger->level($DEBUG); | |||||||||||||||||||||||||||
| 116 | 0 | $soap_logger->level($DEBUG); | |||||||||||||||||||||||||||
| 117 | } else { | ||||||||||||||||||||||||||||
| 118 | 1 | $awapi_logger->level($INFO); | |||||||||||||||||||||||||||
| 119 | 2 | $soap_logger->level($INFO); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | # Disables all logging which includes SOAP Traffic logging and API Errors | ||||||||||||||||||||||||||||
| 124 | # logging. | ||||||||||||||||||||||||||||
| 125 | 1 | ▶ | sub disable_all_logging { | ||||||||||||||||||||||||||
|
Subroutine
disable_all_logging: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 2 | $soap_logger->level($OFF); | |||||||||||||||||||||||||||
| 127 | 2 | $awapi_logger->level($OFF); | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # Retrieves the SOAP logger used to log SOAP requests and responses. | ||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub get_soap_logger { | ||||||||||||||||||||||||||
|
Subroutine
get_soap_logger: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 132 | 1 | initialize_logging(); | |||||||||||||||||||||||||||
| 133 | 1 | return $soap_logger; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | # Retrieves the AWAPI logger used to log messages and errors. | ||||||||||||||||||||||||||||
| 137 | 16 | ▶ | sub get_awapi_logger { | ||||||||||||||||||||||||||
|
Subroutine
get_awapi_logger: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 138 | 17 | initialize_logging(); | |||||||||||||||||||||||||||
| 139 | 17 | return $awapi_logger; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 1 | return 1; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =pod | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =head1 NAME | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | Google::Ads::AdWords::Logging | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | The class L<Google::Ads::AdWords::Logging> allows logging of outgoing and | ||||||||||||||||||||||||||||
| 153 | incoming SOAP XML messages as API calls are executed. It initializes loggers | ||||||||||||||||||||||||||||
| 154 | based on a provided log4perl.conf file or if the file is not found then based | ||||||||||||||||||||||||||||
| 155 | on default parameters. It contains method to retrieve the message loggers. | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =head1 METHODS | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =head2 disable_all_logging | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | Stops all logging. | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =head2 disable_awapi_logging | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | Disables all logging for program errors and messages. | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =head2 disable_soap_logging | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | Disables all logging for soap traffic, request and responses. | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =head2 enable_all_logging | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | Enables all logging. | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =head3 Parameters | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | A boolean if true will also include the logging of low level DEBUG messages. | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =head2 enable_awapi_logging | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | Enables all logging for program errors and messages. | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =head3 Parameters | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | A boolean if true will also include the logging of low level DEBUG messages. | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | =head2 enable_soap_logging | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | Enables all logging for soap traffic, request and responses. | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =head3 Parameters | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | A boolean if true will also include the logging of low level DEBUG messages. | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =head2 get_awapi_logger | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | Retrieves the program errors/messages logger. | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =head3 Returns | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | A log4perl logger for program errors/messages logger. | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =head2 get_soap_logger | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | Retrieves the soap request/response logger. | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | =head3 Returns | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | A log4perl logger for logging soap traffic. | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | Copyright 2011 Google Inc. | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||
| 216 | you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||
| 217 | You may obtain a copy of the License at | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||
| 222 | distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||
| 223 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||
| 224 | See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||
| 225 | limitations under the License. | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | =head1 REPOSITORY INFORMATION | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | $Rev: $ | ||||||||||||||||||||||||||||
| 230 | $LastChangedBy: $ | ||||||||||||||||||||||||||||
| 231 | $Id: $ | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | =cut | ||||||||||||||||||||||||||||