mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-25 02:22:57 +01:00
commit
542503ef2a
41
src/Guzzle/Common/Log/ArrayLogAdapter.php
Normal file
41
src/Guzzle/Common/Log/ArrayLogAdapter.php
Normal 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();
|
||||
}
|
||||
}
|
26
tests/Guzzle/Tests/Common/Log/ArrayLogAdapterTest.php
Normal file
26
tests/Guzzle/Tests/Common/Log/ArrayLogAdapterTest.php
Normal 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());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user