mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-11 23:54:04 +02:00
Merge branch '1.x'
This commit is contained in:
@@ -76,6 +76,7 @@ class LineFormatter extends NormalizerFormatter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach ($vars['context'] as $var => $val) {
|
foreach ($vars['context'] as $var => $val) {
|
||||||
if (false !== strpos($output, '%context.'.$var.'%')) {
|
if (false !== strpos($output, '%context.'.$var.'%')) {
|
||||||
$output = str_replace('%context.'.$var.'%', $this->stringify($val), $output);
|
$output = str_replace('%context.'.$var.'%', $this->stringify($val), $output);
|
||||||
@@ -101,6 +102,11 @@ class LineFormatter extends NormalizerFormatter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove leftover %extra.xxx% and %context.xxx% if any
|
||||||
|
if (false !== strpos($output, '%')) {
|
||||||
|
$output = preg_replace('/%(?:extra|context)\..+?%/', '', $output);
|
||||||
|
}
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -112,7 +112,7 @@ class AmqpHandler extends AbstractProcessingHandler
|
|||||||
* @param array $record
|
* @param array $record
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function getRoutingKey(array $record)
|
protected function getRoutingKey(array $record)
|
||||||
{
|
{
|
||||||
$routingKey = sprintf('%s.%s', $record['level_name'], $record['channel']);
|
$routingKey = sprintf('%s.%s', $record['level_name'], $record['channel']);
|
||||||
|
|
||||||
|
@@ -84,7 +84,7 @@ class RavenHandler extends AbstractProcessingHandler
|
|||||||
|
|
||||||
// the record with the highest severity is the "main" one
|
// the record with the highest severity is the "main" one
|
||||||
$record = array_reduce($records, function ($highest, $record) {
|
$record = array_reduce($records, function ($highest, $record) {
|
||||||
if ($record['level'] >= $highest['level']) {
|
if ($record['level'] > $highest['level']) {
|
||||||
return $record;
|
return $record;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -58,6 +58,8 @@ class RollbarHandler extends AbstractProcessingHandler
|
|||||||
*/
|
*/
|
||||||
private $hasRecords = false;
|
private $hasRecords = false;
|
||||||
|
|
||||||
|
protected $initialized = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param RollbarNotifier $rollbarNotifier RollbarNotifier object constructed with valid token
|
* @param RollbarNotifier $rollbarNotifier RollbarNotifier object constructed with valid token
|
||||||
* @param int $level The minimum logging level at which this handler will be triggered
|
* @param int $level The minimum logging level at which this handler will be triggered
|
||||||
@@ -75,6 +77,12 @@ class RollbarHandler extends AbstractProcessingHandler
|
|||||||
*/
|
*/
|
||||||
protected function write(array $record)
|
protected function write(array $record)
|
||||||
{
|
{
|
||||||
|
if (!$this->initialized) {
|
||||||
|
// __destructor() doesn't get called on Fatal errors
|
||||||
|
register_shutdown_function(array($this, 'close'));
|
||||||
|
$this->initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
$context = $record['context'];
|
$context = $record['context'];
|
||||||
$payload = [];
|
$payload = [];
|
||||||
if (isset($context['payload'])) {
|
if (isset($context['payload'])) {
|
||||||
@@ -105,14 +113,19 @@ class RollbarHandler extends AbstractProcessingHandler
|
|||||||
$this->hasRecords = true;
|
$this->hasRecords = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function flush()
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function close()
|
|
||||||
{
|
{
|
||||||
if ($this->hasRecords) {
|
if ($this->hasRecords) {
|
||||||
$this->rollbarNotifier->flush();
|
$this->rollbarNotifier->flush();
|
||||||
$this->hasRecords = false;
|
$this->hasRecords = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function close()
|
||||||
|
{
|
||||||
|
$this->flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -203,6 +203,32 @@ class RavenHandlerTest extends TestCase
|
|||||||
$handler->handleBatch($records);
|
$handler->handleBatch($records);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testHandleBatchPicksProperMessage()
|
||||||
|
{
|
||||||
|
$records = array(
|
||||||
|
$this->getRecord(Logger::DEBUG, 'debug message 1'),
|
||||||
|
$this->getRecord(Logger::DEBUG, 'debug message 2'),
|
||||||
|
$this->getRecord(Logger::INFO, 'information 1'),
|
||||||
|
$this->getRecord(Logger::ERROR, 'error 1'),
|
||||||
|
$this->getRecord(Logger::WARNING, 'warning'),
|
||||||
|
$this->getRecord(Logger::ERROR, 'error 2'),
|
||||||
|
$this->getRecord(Logger::INFO, 'information 2'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$logFormatter = $this->getMock('Monolog\\Formatter\\FormatterInterface');
|
||||||
|
$logFormatter->expects($this->once())->method('formatBatch');
|
||||||
|
|
||||||
|
$formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface');
|
||||||
|
$formatter->expects($this->once())->method('format')->with($this->callback(function ($record) use ($records) {
|
||||||
|
return $record['message'] == 'error 1';
|
||||||
|
}));
|
||||||
|
|
||||||
|
$handler = $this->getHandler($this->getRavenClient());
|
||||||
|
$handler->setBatchFormatter($logFormatter);
|
||||||
|
$handler->setFormatter($formatter);
|
||||||
|
$handler->handleBatch($records);
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetSetBatchFormatter()
|
public function testGetSetBatchFormatter()
|
||||||
{
|
{
|
||||||
$ravenClient = $this->getRavenClient();
|
$ravenClient = $this->getRavenClient();
|
||||||
|
Reference in New Issue
Block a user