From ea26c8cd225eb1b720b1af72c1ddcd3536ad871c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 29 Apr 2011 13:07:37 +0200 Subject: [PATCH] Added logging to match that used in openruth --- alma.module | 21 ++++++++++++++++++++- lib/AlmaClient.class.php | 37 ++++++++++++++++++++++++------------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/alma.module b/alma.module index 238b103..27939b9 100644 --- a/alma.module +++ b/alma.module @@ -6,7 +6,26 @@ */ /** - * Implement hook_ding_provider(). + * Implements hook_requirements(). + */ +function alma_requirements($phase) { + $requirements = array(); + // Ensure translations don't break at install time. + $t = get_t(); + + if (!function_exists('simplexml_load_string')) { + $requirements['simplexml'] = array( + 'title' => 'SimpleXML', + 'description' => $t('The Alma module requires SimpleXML to function. Please install and/or enable SimpleXML in your PHP configuration.'), + 'severity' => REQUIREMENT_ERROR, + ); + } + + return $requirements; +} + +/** + * Implements hook_ding_provider(). */ function alma_ding_provider() { return array( diff --git a/lib/AlmaClient.class.php b/lib/AlmaClient.class.php index b2a037e..81105fe 100644 --- a/lib/AlmaClient.class.php +++ b/lib/AlmaClient.class.php @@ -25,6 +25,16 @@ class AlmaClient { */ private static $salt; + /** + * Whether we're logging requests. + */ + private $logging = FALSE; + + /** + * Start time of request, used for logging. + */ + private $log_timestamp = NULL; + /** * Constructor, checking if we have a sensible value for $base_url. */ @@ -54,23 +64,24 @@ function __construct($base_url) { * A DOMDocument object with the response. */ public function request($method, $params = array(), $check_status = TRUE) { - $startTime = explode(' ', microtime()); - - // For use with a non-Drupal-system, we should have a way to swap - // the HTTP client out. - $request = drupal_http_request(url($this->base_url . $method, array('query' => $params))); + if ($this->logging) { + $this->log_timestamp = microtime(TRUE); + }; - $stopTime = explode(' ', microtime()); - - // For use with a non-Drupal-system, we should have a way to swap - // logging and logging preferences out. - if (variable_get('alma_enable_logging', FALSE)) { - $seconds = floatval(($stopTime[1]+$stopTime[0]) - ($startTime[1]+$startTime[0])); + // Build the requeste and sent it. + $this->last_request = url($this->base_url . $method, array('query' => $params)); + $request = drupal_http_request($this->last_request); + // Log the request + if ($this->logging) { + $time = round(microtime(TRUE) - $this->log_timestamp, 2); $log_params = self::filter_request_params($params); - // Log the request - watchdog('alma', 'Sent request: @url (@seconds s)', array('@url' => url($this->base_url . $method, array('query' => $log_params)), '@seconds' => $seconds), WATCHDOG_DEBUG); + if ($time) { + watchdog('alma', 'Request (@seconds sec): @url', array('@url' => url($this->base_url . $method, array('query' => $log_params)), '@seconds' => $time), WATCHDOG_DEBUG); + } else { + watchdog('alma', 'Request: @url', array('@url' => url($this->base_url . $method, array('query' => $log_params))), WATCHDOG_DEBUG); + } } if ($request->code == 200) {