mirror of
https://github.com/maximebf/php-debugbar.git
synced 2025-01-16 21:08:34 +01:00
added MonologCollector
This commit is contained in:
parent
3790d3067f
commit
de3274071a
@ -13,7 +13,14 @@
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {"DebugBar": "src/"}
|
||||
},
|
||||
"suggest": {
|
||||
"kriswallsmith/assetic": "The best way to manage assets",
|
||||
"monolog/monolog": "Log using Monolog"
|
||||
}
|
||||
}
|
||||
|
56
src/DebugBar/Bridge/MonologCollector.php
Normal file
56
src/DebugBar/Bridge/MonologCollector.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace DebugBar\Bridge;
|
||||
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\AbstractProcessingHandler;
|
||||
use DebugBar\DataCollector\DataCollectorInterface;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
|
||||
/**
|
||||
* A monolog handler as well as a data collector
|
||||
*
|
||||
* <code>
|
||||
* $debugbar->addCollector(new MonologCollector($logger));
|
||||
* </code>
|
||||
*/
|
||||
class MonologCollector extends AbstractProcessingHandler implements DataCollectorInterface, Renderable
|
||||
{
|
||||
protected $records = array();
|
||||
|
||||
public function __construct(Logger $logger, $level = Logger::DEBUG, $bubble = true)
|
||||
{
|
||||
$logger->pushHandler($this);
|
||||
}
|
||||
|
||||
protected function write(array $record)
|
||||
{
|
||||
$this->records[] = array(
|
||||
'message' => $record['formatted'],
|
||||
'is_string' => true,
|
||||
'label' => strtolower($record['level_name']),
|
||||
'time' => $record['datetime']->format('U')
|
||||
);
|
||||
}
|
||||
|
||||
public function collect()
|
||||
{
|
||||
return $this->records;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'monolog';
|
||||
}
|
||||
|
||||
public function getWidgets()
|
||||
{
|
||||
return array(
|
||||
"logs" => array(
|
||||
"widget" => "PhpDebugBar.Widgets.MessagesWidget",
|
||||
"map" => "monolog",
|
||||
"default" => "[]"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user