Closed fsateler closed 3 years ago
Our tiny extension here was written for logging from docker containers but should probably also work in your case:
@mikehaertl Interesting, will look into that extension. Thanks! I still think yii should provide this out of the box.
@fsateler yii2-streamlog
is a highly reliable extension, we're using it since over 2 years in all projects (>50) and never had any problems with it.
The extension is good as many other extensions by codemix team but I'm not sure if it is a good idea to make it part of the core and use it by default.
Actually, Yii prints out error messages by default in the command line mode.
So I'd need a way to reproduce the case when it's not doing so.
The extension is good as many other extensions by codemix team but I'm not sure if it is a good idea to make it part of the core and use it by default.
You should have some kind of extensions which are let's say "recommended, but without official support from the core team", codemix has several of those, creocoder, cebe and 2amigos also. dektrium/user is also widely used and of high quality.
This would take some weight of your shoulders, while also giving the community some hints about which extensions to chose or try first.
Just as an example ;) You don't need to create any more extensions https://github.com/schmunk42/yii2-extension-requests/issues/8#issuecomment-39006307
Actually, Yii prints out error messages by default in the command line mode.
That's a matter of configuration, i.e. we have this for all application types/common
'log' => [
'targets' => [
[
'class' => 'codemix\streamlog\Target',
'url' => 'php://stderr',
'levels' => ['error', 'warning'],
'logVars' => [],
],
],
],
@schmunk42 Indeed, that is what I have been using since. And I wouldn't mind the template to come configured as you did (like I do for my projects now). Yii already depends on third-party components, so adding a new one wouldn't bother me.
@samdark Warning messages are not printed as errors:
composer create-project yiisoft/yii2-app-basic
cd yii2-app-basic
# simulate a cache written by the server
mkdir runtime/cache/test
touch runtime/cache/test/test
sudo chown --recursive www-data:www-data runtime/cache/test
# and then a flush as user
php yii cache/flush-all
The following cache components were processed:
* cache (yii\caching\FileCache)
# Cool! everything worked, right? nope
find runtime/cache
runtime/cache
runtime/cache/test
runtime/cache/test/test
# But yii is a good framework, it logs about such things:
grep warning runtime/logs/app.log
2017-01-10 00:26:46 [-][-][-][warning][yii\caching\FileCache::gcRecursive] Unable to remove file '/tmp/yii2-app-basic/runtime/cache/test/test': unlink(/tmp/yii2-app-basic/runtime/cache/test/test): Permission denied
2017-01-10 00:26:46 [-][-][-][warning][yii\caching\FileCache::gcRecursive] Unable to remove directory '/tmp/yii2-app-basic/runtime/cache/test': rmdir(/tmp/yii2-app-basic/runtime/cache/test): Directory not empty
However, that last step would not have worked if the log file was also owned by the www-data
group, as yii would not have been able to write to it.
That's strange, have a look at these build warnings, the warning is shown in the console, with the settings I've linked above. And also written to console.log
How is the app.log
file created, with a FileLogRoute
or because output get's send to stderr
?
Do you expect output to be in error.log
or on your console?
As a workaround: You might try configuring error output to stdout
.
@schmunk42 I was talking when yii does not have the streamlog configured (that is, the default configuration). With the streamlog configuration they are printed to stderr.
Need to verify that. If there's no errors outputted then it worth having in the core and using by default.
I've wrote StdoutTarget
for asset-packagist.org recently. sources
Had to set exportInterval
and flushInterval
to 1 in order to have messages printed immediately.
Shouldn't this Logger be in yii-console instead?
Could be, yes.
I have been bitten quite a few times when (for example) cache/flush-all doesn't work because of permissions issue (say, the cache files are owned by www-data), and in turn the error messages are redirected to the app log... which can't be written because it is owned by www-data too.
The console commands should default to printing everything on stderr, and that should include warning/error log messages.