I had set up log
component with FileTarget
in the main config and expected Yii::error()
will write messages in the file when I will launch tests. But logging was catched up by Codeception\Lib\Connector\Yii2\Logger
and log folder remains empty.
Is it possible to make Yii2 write logs in this situation?
You can configure correct logger before test:
public function testSomething() {
Yii::setLogger(Yii::createObject(\yii\log\Logger::class));
Yii::$app->log->setLogger(Yii::getLogger());
// log something
Yii::getLogger()->flush();
// test log file
}
<?php
namespace tests;
class SomeTest extends \yii\codeception\TestCase
{
public function testLogMessage()
{
\Yii::error('something bad occurred');
}
}
And this correctly logs error under runtime/log/app.log with message:
2018/05/05 03:42:04 [127.0.0.1] [error] [application] something bad occurred
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With