Last active
August 29, 2015 14:14
-
-
Save iainp999/250033b61c4ebb02ed40 to your computer and use it in GitHub Desktop.
Guzzle log adaptor for Drupal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Log messages using Drupal watchdog. | |
*/ | |
class DrupalLogAdaptor implements \Guzzle\Log\LogAdapterInterface { | |
private $type = 'guzzle'; | |
/** | |
* @param string $type | |
*/ | |
function __construct($type = 'guzzle') { | |
$this->type = $type; | |
} | |
/** | |
* Log a message at a priority | |
* | |
* @param string $message Message to log | |
* @param integer $priority Priority of message (use the \LOG_* constants of 0 - 7) | |
* @param array $extras Extra information to log in event | |
*/ | |
public function log($message, $priority = LOG_INFO, $extras = array()) { | |
watchdog($this->type, $message, $variables = array(), $this->mapPriority($priority)); | |
} | |
/** | |
* Map a Guzzle priority to a Drupal severity. | |
*/ | |
protected function mapPriority($priority) { | |
switch($priority) { | |
case LOG_ALERT: | |
return WATCHDOG_ALERT; | |
case LOG_CRIT: | |
return WATCHDOG_CRITICAL; | |
case LOG_DEBUG: | |
return WATCHDOG_DEBUG; | |
case LOG_EMERG: | |
return WATCHDOG_EMERGENCY; | |
case LOG_ERR: | |
return WATCHDOG_ERROR; | |
case LOG_INFO: | |
return WATCHDOG_INFO; | |
case LOG_WARNING: | |
return WATCHDOG_WARNING; | |
default: | |
return WATCHDOG_NOTICE; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
e.g.