Commit 38c056c7 by Alexander Makarov

Moved handling from Target to Dispatcher, fixed edge cases

parent a92dd65e
......@@ -175,10 +175,26 @@ class Dispatcher extends Component
*/
public function dispatch($messages, $final)
{
$targetErrors = [];
foreach ($this->targets as $target) {
if ($target->enabled) {
$target->collect($messages, $final);
try {
$target->collect($messages, $final);
} catch (\Exception $e) {
$target->enabled = false;
$targetErrors[] = [
'Unable to send log via '. get_class($target) .': ' . $e->getMessage(),
Logger::LEVEL_WARNING,
__METHOD__,
microtime(true),
[],
];
}
}
}
if (!empty($targetErrors)) {
$this->dispatch($targetErrors, true);
}
}
}
......@@ -105,13 +105,7 @@ abstract class Target extends Component
if (($context = $this->getContextMessage()) !== '') {
$this->messages[] = [$context, Logger::LEVEL_INFO, 'application', YII_BEGIN_TIME];
}
try {
$this->export();
} catch (\Exception $e) {
$this->enabled = false;
\Yii::warning('Unable to send log via '. get_class($this) .': ' . $e->getMessage(), __METHOD__);
\Yii::getLogger()->flush(true);
}
$this->export();
$this->messages = [];
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment