New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix logger for case Yii::$app lost on process exiting #6549
Fix logger for case Yii::$app lost on process exiting #6549
Conversation
Logger::flush() might be called by register_shutdown_function() when application instance has gone.
Why do you have the logger configured in your Tests? Should be skipped IMO because it will result in n shutdown functions to be registered for n tests... |
Which does "Tests" point (a) my own app's tests using Codeception or (b) test added while this PR? (a) I'm using single logger instance stored in 'Yii::$_logger' commonly. My problem is that actually PHP crashed at the end of
My app has no special config. [
'components' => [
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
], Perhaps some of my functions called |
Similar result would be displayed by below code. Yii::error("test");
Yii::$app = null;
exit; |
@cebe to be true i already faced with 2 - 5 such examples here in issues about |
I am asking why you need to enable the log dispatcher in the test application? If you create a new instance for each test case you will spam the logfiles which you do not need and it will also make your tests slower. To avoid this problem, just do not configure a log component in application. In normal envirnoment there is no reason to unset |
related to #6102 |
It is the problem that developers dont throw exceptions ( |
but are you using these logs when running tests to determine the state of the tests or evaluate them? |
i dont use this logs , i just throw an exception if something goes not according contracts ) |
yeah, this questions was more directed to the issue starter :) |
@cebe Because current both application template basic and advanced are reusing app config and do not redefine log dispatcher for tests. |
It is already resolved by b338240 |
Logger::flush()
might be called byregister_shutdown_function()
when application instance has gone.In fact, Codeception extension clears
Yii::$app
on every test cases.yii2/extensions/codeception/TestCase.php
Line 129 in c9d51ee