1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-25 10:36:33 +02:00

Merge branch '1.x'

This commit is contained in:
Jordi Boggiano
2016-05-20 19:40:36 +01:00
11 changed files with 223 additions and 37 deletions

View File

@@ -81,6 +81,26 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
return true;
}
/**
* Manually activate this logger regardless of the activation strategy
*/
public function activate()
{
if ($this->stopBuffering) {
$this->buffering = false;
}
if (!$this->handler instanceof HandlerInterface) {
$record = end($this->buffer) ?: null;
$this->handler = call_user_func($this->handler, $record, $this);
if (!$this->handler instanceof HandlerInterface) {
throw new \RuntimeException("The factory callable should return a HandlerInterface");
}
}
$this->handler->handleBatch($this->buffer);
$this->buffer = array();
}
/**
* {@inheritdoc}
*/
@@ -96,17 +116,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa
array_shift($this->buffer);
}
if ($this->activationStrategy->isHandlerActivated($record)) {
if ($this->stopBuffering) {
$this->buffering = false;
}
if (!$this->handler instanceof HandlerInterface) {
$this->handler = call_user_func($this->handler, $record, $this);
if (!$this->handler instanceof HandlerInterface) {
throw new \RuntimeException("The factory callable should return a HandlerInterface");
}
}
$this->handler->handleBatch($this->buffer);
$this->buffer = array();
$this->activate();
}
} else {
$this->handler->handle($record);

View File

@@ -92,23 +92,27 @@ class NewRelicHandler extends AbstractProcessingHandler
newrelic_notice_error($record['message']);
}
foreach ($record['formatted']['context'] as $key => $parameter) {
if (is_array($parameter) && $this->explodeArrays) {
foreach ($parameter as $paramKey => $paramValue) {
$this->setNewRelicParameter('context_' . $key . '_' . $paramKey, $paramValue);
if (isset($record['formatted']['context'])) {
foreach ($record['formatted']['context'] as $key => $parameter) {
if (is_array($parameter) && $this->explodeArrays) {
foreach ($parameter as $paramKey => $paramValue) {
$this->setNewRelicParameter('context_' . $key . '_' . $paramKey, $paramValue);
}
} else {
$this->setNewRelicParameter('context_' . $key, $parameter);
}
} else {
$this->setNewRelicParameter('context_' . $key, $parameter);
}
}
foreach ($record['formatted']['extra'] as $key => $parameter) {
if (is_array($parameter) && $this->explodeArrays) {
foreach ($parameter as $paramKey => $paramValue) {
$this->setNewRelicParameter('extra_' . $key . '_' . $paramKey, $paramValue);
if (isset($record['formatted']['extra'])) {
foreach ($record['formatted']['extra'] as $key => $parameter) {
if (is_array($parameter) && $this->explodeArrays) {
foreach ($parameter as $paramKey => $paramValue) {
$this->setNewRelicParameter('extra_' . $key . '_' . $paramKey, $paramValue);
}
} else {
$this->setNewRelicParameter('extra_' . $key, $parameter);
}
} else {
$this->setNewRelicParameter('extra_' . $key, $parameter);
}
}
}

View File

@@ -24,6 +24,10 @@ use Monolog\Logger;
*/
class RotatingFileHandler extends StreamHandler
{
const FILE_PER_DAY = 'Y-m-d';
const FILE_PER_MONTH = 'Y-m';
const FILE_PER_YEAR = 'Y';
protected $filename;
protected $maxFiles;
protected $mustRotate;
@@ -64,6 +68,20 @@ class RotatingFileHandler extends StreamHandler
public function setFilenameFormat($filenameFormat, $dateFormat)
{
if (!in_array($dateFormat, array(self::FILE_PER_DAY, self::FILE_PER_MONTH, self::FILE_PER_YEAR))) {
trigger_error(
'Invalid date format - format should be one of '.
'RotatingFileHandler::FILE_PER_DAY, RotatingFileHandler::FILE_PER_MONTH '.
'or RotatingFileHandler::FILE_PER_YEAR.',
E_USER_DEPRECATED
);
}
if (substr_count($filenameFormat, '{date}') === 0) {
trigger_error(
'Invalid filename format - format should contain at least `{date}`, because otherwise rotating is impossible.',
E_USER_DEPRECATED
);
}
$this->filenameFormat = $filenameFormat;
$this->dateFormat = $dateFormat;
$this->url = $this->getTimedFilename();

View File

@@ -35,6 +35,8 @@ class WhatFailureGroupHandler extends GroupHandler
$handler->handle($record);
} catch (\Exception $e) {
// What failure?
} catch (\Throwable $e) {
// What failure?
}
}
@@ -51,6 +53,8 @@ class WhatFailureGroupHandler extends GroupHandler
$handler->handleBatch($records);
} catch (\Exception $e) {
// What failure?
} catch (\Throwable $e) {
// What failure?
}
}
}