Skip to content

Commit

Permalink
Added logging to match that used in openruth
Browse files Browse the repository at this point in the history
  • Loading branch information
cableman committed Apr 29, 2011
1 parent 352221f commit ea26c8c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
21 changes: 20 additions & 1 deletion alma.module
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
37 changes: 24 additions & 13 deletions lib/AlmaClient.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ea26c8c

Please sign in to comment.