mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-07 05:36:45 +02:00
Move handler checks in constructor
This commit is contained in:
@@ -55,6 +55,10 @@ class FilterHandler extends AbstractHandler
|
||||
$this->handler = $handler;
|
||||
$this->bubble = $bubble;
|
||||
$this->setAcceptedLevels($minLevelOrList, $maxLevel);
|
||||
|
||||
if (!$this->handler instanceof HandlerInterface && !is_callable($this->handler)) {
|
||||
throw new \RuntimeException("The given handler (".json_encode($this->handler).") is not a callable nor a Monolog\Handler\HandlerInterface object");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,12 +106,6 @@ class FilterHandler extends AbstractHandler
|
||||
|
||||
// The same logic as in FingersCrossedHandler
|
||||
if (!$this->handler instanceof HandlerInterface) {
|
||||
if (!is_callable($this->handler)) {
|
||||
throw new \RuntimeException(
|
||||
"The given handler (" . json_encode($this->handler)
|
||||
. ") is not a callable nor a Monolog\\Handler\\HandlerInterface object"
|
||||
);
|
||||
}
|
||||
$this->handler = call_user_func($this->handler, $record, $this);
|
||||
if (!$this->handler instanceof HandlerInterface) {
|
||||
throw new \RuntimeException("The factory callable should return a HandlerInterface");
|
||||
|
@@ -62,6 +62,10 @@ class FingersCrossedHandler extends AbstractHandler
|
||||
$this->bubble = $bubble;
|
||||
$this->stopBuffering = $stopBuffering;
|
||||
$this->passthruLevel = $passthruLevel;
|
||||
|
||||
if (!$this->handler instanceof HandlerInterface && !is_callable($this->handler)) {
|
||||
throw new \RuntimeException("The given handler (".json_encode($this->handler).") is not a callable nor a Monolog\Handler\HandlerInterface object");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,9 +97,6 @@ class FingersCrossedHandler extends AbstractHandler
|
||||
$this->buffering = false;
|
||||
}
|
||||
if (!$this->handler instanceof HandlerInterface) {
|
||||
if (!is_callable($this->handler)) {
|
||||
throw new \RuntimeException("The given handler (".json_encode($this->handler).") is not a callable nor a Monolog\Handler\HandlerInterface object");
|
||||
}
|
||||
$this->handler = call_user_func($this->handler, $record, $this);
|
||||
if (!$this->handler instanceof HandlerInterface) {
|
||||
throw new \RuntimeException("The factory callable should return a HandlerInterface");
|
||||
|
@@ -48,6 +48,10 @@ class SamplingHandler extends AbstractHandler
|
||||
parent::__construct();
|
||||
$this->handler = $handler;
|
||||
$this->factor = $factor;
|
||||
|
||||
if (!$this->handler instanceof HandlerInterface && !is_callable($this->handler)) {
|
||||
throw new \RuntimeException("The given handler (".json_encode($this->handler).") is not a callable nor a Monolog\Handler\HandlerInterface object");
|
||||
}
|
||||
}
|
||||
|
||||
public function isHandling(array $record)
|
||||
@@ -60,12 +64,6 @@ class SamplingHandler extends AbstractHandler
|
||||
if ($this->isHandling($record) && mt_rand(1, $this->factor) === 1) {
|
||||
// The same logic as in FingersCrossedHandler
|
||||
if (!$this->handler instanceof HandlerInterface) {
|
||||
if (!is_callable($this->handler)) {
|
||||
throw new \RuntimeException(
|
||||
"The given handler (" . json_encode($this->handler)
|
||||
. ") is not a callable nor a Monolog\\Handler\\HandlerInterface object"
|
||||
);
|
||||
}
|
||||
$this->handler = call_user_func($this->handler, $record, $this);
|
||||
if (!$this->handler instanceof HandlerInterface) {
|
||||
throw new \RuntimeException("The factory callable should return a HandlerInterface");
|
||||
|
Reference in New Issue
Block a user