1
0
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:
maximebf 2013-06-13 20:23:22 +08:00
parent 3790d3067f
commit de3274071a
2 changed files with 63 additions and 0 deletions

View File

@ -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"
}
}

View 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" => "[]"
)
);
}
}