diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index de9baca06c..7f00124aae 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -20,6 +20,7 @@ Yii Framework 2 Change Log - Enh #6467: `ActiveForm` will scroll to the nearest visible element when the first error input is hidden (newartix) - Enh #6488: Support changing `yii\base\Theme::basePath` during runtime (qiangxue) - Enh #6618: Added Model::addErrors() (slavcodev, pana1990) +- Enh #6739: Log `Target` now works also when there is no `Yii::$app` instance available, no message prefix will be added in this case (schmunk42) - Chg #6427: In case of invalid route web application now throws exception with "Page not found" instead of "Invalid Route" (cebe, samdark) - Chg #6641: removed zero padding from ETag strings (DaSourcerer) - Chg #6678: `yii\behaviors\SluggableBehavior` will generate a new slug only when the slug attribute is empty or the source attribute is changed (qiangxue) diff --git a/framework/log/Target.php b/framework/log/Target.php index d05bdbf4e2..8d4ca6083b 100644 --- a/framework/log/Target.php +++ b/framework/log/Target.php @@ -266,6 +266,10 @@ abstract class Target extends Component return call_user_func($this->prefix, $message); } + if (Yii::$app === null) { + return ''; + } + $request = Yii::$app->getRequest(); $ip = $request instanceof Request ? $request->getUserIP() : '-';