diff --git a/CHANGELOG.md b/CHANGELOG.md index 66f6bec4..db645cc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Release Notes for Campaign -## 2.12.2 - Unreleased +## 2.12.2 - 2024-03-05 + +### Changed + +- A custom log target is now only registered if a dispatcher exists. ### Security diff --git a/src/Campaign.php b/src/Campaign.php index 23db104c..2c4c5e5f 100644 --- a/src/Campaign.php +++ b/src/Campaign.php @@ -84,6 +84,7 @@ use yii\base\Controller; use yii\base\Event; use yii\di\Instance; +use yii\log\Dispatcher; use yii\log\Logger; use yii\queue\Queue; use yii\web\ForbiddenHttpException; @@ -513,17 +514,19 @@ function(Event $event) { */ private function _registerLogTarget(): void { - Craft::getLogger()->dispatcher->targets[] = new MonologTarget([ - 'name' => 'campaign', - 'categories' => ['campaign'], - 'level' => LogLevel::INFO, - 'logContext' => false, - 'allowLineBreaks' => false, - 'formatter' => new LineFormatter( - format: "[%datetime%] %message%\n", - dateFormat: 'Y-m-d H:i:s', - ), - ]); + if (Craft::getLogger()->dispatcher instanceof Dispatcher) { + Craft::getLogger()->dispatcher->targets[] = new MonologTarget([ + 'name' => 'campaign', + 'categories' => ['campaign'], + 'level' => LogLevel::INFO, + 'logContext' => false, + 'allowLineBreaks' => false, + 'formatter' => new LineFormatter( + format: "[%datetime%] %message%\n", + dateFormat: 'Y-m-d H:i:s', + ), + ]); + } } /**