Browse Source

Fix #18840: Fix `yii2/log/Logger` to set logger globally

tags/2.0.44
lexizz 3 years ago committed by GitHub
parent
commit
383241f65c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      framework/CHANGELOG.md
  2. 4
      framework/log/Dispatcher.php
  3. 11
      tests/framework/log/DispatcherTest.php

1
framework/CHANGELOG.md

@ -8,6 +8,7 @@ Yii Framework 2 Change Log
- Enh #18826: Add ability to turn the sorting off for a clicked column in GridView with multisort (ditibal)
- Bug #18646: Remove stale identity data from session if `IdentityInterface::findIdentity()` returns `null` (mikehaertl)
- Bug #18832: Fix `Inflector::camel2words()` adding extra spaces (brandonkelly)
- Bug #18840: Fix `yii2/log/Logger` to set logger globally (lexizz)
2.0.43 August 09, 2021

4
framework/log/Dispatcher.php

@ -10,6 +10,7 @@ namespace yii\log;
use Yii;
use yii\base\Component;
use yii\base\ErrorHandler;
use yii\base\InvalidConfigException;
/**
* Dispatcher manages a set of [[Target|log targets]].
@ -123,13 +124,16 @@ class Dispatcher extends Component
* Sets the connected logger.
* @param Logger|string|array $value the logger to be used. This can either be a logger instance
* or a configuration that will be used to create one using [[Yii::createObject()]].
* @throws InvalidConfigException
*/
public function setLogger($value)
{
if (is_string($value) || is_array($value)) {
$value = Yii::createObject($value);
}
$this->_logger = $value;
Yii::setLogger($value);
$this->_logger->dispatcher = $this;
}

11
tests/framework/log/DispatcherTest.php

@ -18,6 +18,7 @@ namespace yii\log {
namespace yiiunit\framework\log {
use yii\BaseYii;
use yiiunit\framework\log\mocks\TargetMock;
use Yii;
use yii\base\UserException;
@ -87,6 +88,16 @@ namespace yiiunit\framework\log {
]);
$this->assertInstanceOf('yii\log\Logger', $dispatcher->getLogger());
$this->assertEquals(42, $dispatcher->getLogger()->traceLevel);
$dispatcher = new Dispatcher([
'logger' => [
'class' => 'yii\log\Logger',
'profilingAware' => true,
],
]);
$this->assertInstanceOf('yii\log\Logger', $dispatcher->getLogger());
$this->assertEquals(true, $dispatcher->getLogger()->profilingAware);
$this->assertEquals(true, BaseYii::getLogger()->profilingAware);
}
/**

Loading…
Cancel
Save