yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

Log timezone and formatter->timezone #14687

Open bscheshirwork opened 7 years ago

bscheshirwork commented 7 years ago

I have \Yii2::$app->formatter->defaultTimeZone not equal php timezone

I can see framework/log/Target.php#L273-L274 framework/log/Target.php#L119

So... I can get a message time with php timezone instead of a yii2 application default timezone in all cases?

I expect a time value in log is native for yii2 application if \Yii2::$app->formatter->defaultTimeZone is set.

The yii\i18n\Formatter|formatter is a build-in component, any apps can use it, right?

But i must use additional settings - yii\base\Application::timeZone|timeZone

I think need tell about this differences as a note in the formatter and log chapters.

Additional info

Q A
Yii version dev
PHP version 7.1.8
Operating system
cebe commented 7 years ago

So... I can get a message time with php timezone instead of a yii2 application default timezone in all cases?

have you read the docs of defaultTimeZone? It is used to determine the timezone of values in the database, which are formatted and converted to timeZone. So setting defaultTimezone should not affect log formatting at all.

bscheshirwork commented 7 years ago

@cebe I tell about update docs...

It is used to determine the timezone of values in the database

I read guide formatting. I don't see "database" (without ICU database) I read guide log I don't see anything about timezone. Only one time timestamp in Message Formatting.

I think can be add to example settings additional line

return [
    // the "log" component must be loaded during bootstrapping time
    'bootstrap' => ['log'],
    // the "log" component process messages with timestamp. Set php timezone to create correct timestamp
    'timeZone' => 'America/Los_Angeles',
    'components' => [
        'log' => [
            'targets' => [
                [
                    'class' => 'yii\log\DbTarget',
                    'levels' => ['error', 'warning'],
                ],
                [
                    'class' => 'yii\log\EmailTarget',
                    'levels' => ['error'],
                    'categories' => ['yii\db\*'],
                    'message' => [
                       'from' => ['log@example.com'],
                       'to' => ['admin@example.com', 'developer@example.com'],
                       'subject' => 'Database errors at example.com',
                    ],
                ],
            ],
        ],
    ],
];