mirror of
https://github.com/Seldaek/monolog.git
synced 2025-02-24 06:52:34 +01:00
Merge remote-tracking branch 'schmittjoh/actStrat'
This commit is contained in:
commit
fa50158f78
28
src/Monolog/Handler/FingersCrossed/ActivationStrategyInterface.php
Executable file
28
src/Monolog/Handler/FingersCrossed/ActivationStrategyInterface.php
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Monolog package.
|
||||||
|
*
|
||||||
|
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Monolog\Handler\FingersCrossed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for activation strategies for the FingersCrossedHandler.
|
||||||
|
*
|
||||||
|
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||||
|
*/
|
||||||
|
interface ActivationStrategyInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns whether the given record activates the handler.
|
||||||
|
*
|
||||||
|
* @param array $record
|
||||||
|
* @return Boolean
|
||||||
|
*/
|
||||||
|
function isHandlerActivated(array $record);
|
||||||
|
}
|
32
src/Monolog/Handler/FingersCrossed/ErrorLevelActivationStrategy.php
Executable file
32
src/Monolog/Handler/FingersCrossed/ErrorLevelActivationStrategy.php
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Monolog package.
|
||||||
|
*
|
||||||
|
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Monolog\Handler\FingersCrossed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error level based activation strategy.
|
||||||
|
*
|
||||||
|
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||||
|
*/
|
||||||
|
class ErrorLevelActivationStrategy implements ActivationStrategyInterface
|
||||||
|
{
|
||||||
|
private $actionLevel;
|
||||||
|
|
||||||
|
public function __construct($actionLevel)
|
||||||
|
{
|
||||||
|
$this->actionLevel = $actionLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isHandlerActivated(array $record)
|
||||||
|
{
|
||||||
|
return $record['level'] >= $this->actionLevel;
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Monolog\Handler;
|
namespace Monolog\Handler;
|
||||||
|
|
||||||
|
use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy;
|
||||||
|
use Monolog\Handler\FingersCrossed\ActivationStrategyInterface;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,7 +27,7 @@ use Monolog\Logger;
|
|||||||
class FingersCrossedHandler extends AbstractHandler
|
class FingersCrossedHandler extends AbstractHandler
|
||||||
{
|
{
|
||||||
protected $handler;
|
protected $handler;
|
||||||
protected $actionLevel;
|
protected $activationStrategy;
|
||||||
protected $buffering = true;
|
protected $buffering = true;
|
||||||
protected $bufferSize;
|
protected $bufferSize;
|
||||||
protected $buffer = array();
|
protected $buffer = array();
|
||||||
@ -33,15 +35,22 @@ class FingersCrossedHandler extends AbstractHandler
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param callback|HandlerInterface $handler Handler or factory callback($record, $fingersCrossedHandler).
|
* @param callback|HandlerInterface $handler Handler or factory callback($record, $fingersCrossedHandler).
|
||||||
* @param int $actionLevel The minimum logging level at which this handler will be triggered
|
* @param int|ActivationStrategyInterface $activationStrategy Strategy which determines when this handler takes action
|
||||||
* @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
|
* @param int $bufferSize How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
|
||||||
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
|
* @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
|
||||||
* @param Boolean $stopBuffering Whether the handler should stop buffering after being triggered (default true)
|
* @param Boolean $stopBuffering Whether the handler should stop buffering after being triggered (default true)
|
||||||
*/
|
*/
|
||||||
public function __construct($handler, $actionLevel = Logger::WARNING, $bufferSize = 0, $bubble = true, $stopBuffering = true)
|
public function __construct($handler, $activationStrategy = null, $bufferSize = 0, $bubble = true, $stopBuffering = true)
|
||||||
{
|
{
|
||||||
|
if (null === $activationStrategy) {
|
||||||
|
$activationStrategy = new ErrorLevelActivationStrategy(Logger::WARNING);
|
||||||
|
}
|
||||||
|
if (!$activationStrategy instanceof ActivationStrategyInterface) {
|
||||||
|
$activationStrategy = new ErrorLevelActivationStrategy($activationStrategy);
|
||||||
|
}
|
||||||
|
|
||||||
$this->handler = $handler;
|
$this->handler = $handler;
|
||||||
$this->actionLevel = $actionLevel;
|
$this->activationStrategy = $activationStrategy;
|
||||||
$this->bufferSize = $bufferSize;
|
$this->bufferSize = $bufferSize;
|
||||||
$this->bubble = $bubble;
|
$this->bubble = $bubble;
|
||||||
$this->stopBuffering = $stopBuffering;
|
$this->stopBuffering = $stopBuffering;
|
||||||
@ -65,7 +74,7 @@ class FingersCrossedHandler extends AbstractHandler
|
|||||||
if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) {
|
if ($this->bufferSize > 0 && count($this->buffer) > $this->bufferSize) {
|
||||||
array_shift($this->buffer);
|
array_shift($this->buffer);
|
||||||
}
|
}
|
||||||
if ($record['level'] >= $this->actionLevel) {
|
if ($this->activationStrategy->isHandlerActivated($record)) {
|
||||||
if ($this->stopBuffering) {
|
if ($this->stopBuffering) {
|
||||||
$this->buffering = false;
|
$this->buffering = false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user