Browse Source

ensure log dispatcher gets registered with logger in all cases

fixes #2894
tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
093f5ebd32
  1. 6
      framework/log/Dispatcher.php
  2. 3
      tests/unit/framework/log/LoggerTest.php
  3. 3
      tests/unit/framework/log/TargetTest.php

6
framework/log/Dispatcher.php

@ -78,7 +78,7 @@ class Dispatcher extends Component
public function __construct($config = []) public function __construct($config = [])
{ {
if (isset($config['logger'])) { if (isset($config['logger'])) {
$this->_logger = $config['logger']; $this->setLogger($config['logger']);
unset($config['logger']); unset($config['logger']);
} }
// connect logger and dispatcher // connect logger and dispatcher
@ -110,8 +110,7 @@ class Dispatcher extends Component
public function getLogger() public function getLogger()
{ {
if ($this->_logger === null) { if ($this->_logger === null) {
$this->_logger = Yii::getLogger(); $this->setLogger(Yii::getLogger());
$this->_logger->dispatcher = $this;
} }
return $this->_logger; return $this->_logger;
} }
@ -123,6 +122,7 @@ class Dispatcher extends Component
public function setLogger($value) public function setLogger($value)
{ {
$this->_logger = $value; $this->_logger = $value;
$this->_logger->dispatcher = $this;
} }
/** /**

3
tests/unit/framework/log/LoggerTest.php

@ -8,6 +8,9 @@ namespace yiiunit\framework\log;
use yii\log\Logger; use yii\log\Logger;
use yiiunit\TestCase; use yiiunit\TestCase;
/**
* @group log
*/
class LoggerTest extends TestCase class LoggerTest extends TestCase
{ {

3
tests/unit/framework/log/TargetTest.php

@ -10,6 +10,9 @@ use yii\log\Logger;
use yii\log\Target; use yii\log\Target;
use yiiunit\TestCase; use yiiunit\TestCase;
/**
* @group log
*/
class TargetTest extends TestCase class TargetTest extends TestCase
{ {
public static $messages; public static $messages;

Loading…
Cancel
Save