1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-25 02:22:57 +01:00

Merge pull request #69 from gimler/array_adapter

add array log adapter
This commit is contained in:
Michael Dowling 2012-06-12 10:11:43 -07:00
commit 542503ef2a
2 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,41 @@
<?php
namespace Guzzle\Common\Log;
use Guzzle\Common\Log\LogAdapterInterface;
/**
* Adapter class that allows Guzzle to log data to various logging
* implementations so that you may use the log classes of your favorite
* framework.
*/
class ArrayLogAdapter implements LogAdapterInterface
{
protected $logs = array();
/**
* {@inheritdoc}
*/
public function log($message, $priority = LOG_INFO, $extras = null)
{
$this->logs[] = array('message' => $message, 'priority' => $priority, 'extras' => $extras);
}
/**
* Get logged entries
*
* @return array
*/
public function getLogs()
{
return $this->logs;
}
/**
* Clears logged entries
*/
public function clearLogs()
{
$this->logs = array();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace Guzzle\Tests\Common\Log;
use Guzzle\Common\Log\LogAdapterInterface;
use Guzzle\Common\Log\ArrayLogAdapter;
class ArrayLogAdapterTest extends \Guzzle\Tests\GuzzleTestCase
{
public function testLog()
{
$adapter = new ArrayLogAdapter();
$adapter->log('test', \LOG_NOTICE, 'localhost');
$this->assertEquals(array(array('message' => 'test', 'priority' => \LOG_NOTICE, 'extras' => 'localhost')), $adapter->getLogs());
}
public function testClearLog()
{
$adapter = new ArrayLogAdapter();
$adapter->log('test', \LOG_NOTICE, 'localhost');
$adapter->clearLogs();
$this->assertEquals(array(), $adapter->getLogs());
}
}