yiisoft / log

PSR-3 compatible logger
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
40 stars 17 forks source link

Wish: Add LogTarget that prints to standard output, and make it default in console config #20

Closed fsateler closed 3 years ago

fsateler commented 9 years ago

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.

mikehaertl commented 9 years ago

Our tiny extension here was written for logging from docker containers but should probably also work in your case:

https://github.com/codemix/yii2-streamlog

fsateler commented 9 years ago

@mikehaertl Interesting, will look into that extension. Thanks! I still think yii should provide this out of the box.

schmunk42 commented 7 years ago

@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.

samdark commented 7 years ago

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.

samdark commented 7 years ago

Actually, Yii prints out error messages by default in the command line mode.

samdark commented 7 years ago

So I'd need a way to reproduce the case when it's not doing so.

schmunk42 commented 7 years ago

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' => [],
                ],
            ],
        ],

And info & trace for web in DEV mode

fsateler commented 7 years ago

@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.

schmunk42 commented 7 years ago

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.

fsateler commented 7 years ago

@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.

samdark commented 7 years ago

Need to verify that. If there's no errors outputted then it worth having in the core and using by default.

SilverFire commented 7 years ago

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.

machour commented 5 years ago

Shouldn't this Logger be in yii-console instead?

samdark commented 5 years ago

Could be, yes.