yii2日志使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zchqq/article/details/83145838

console.php中配置,如果需要在windows环境下执行,还需在web.php中配置

'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning','trace','info'],
                ],

                //以文件的方式记录
                [
                    'class'          => 'yii\log\FileTarget',
                    'levels'         => ['info'],
                    'categories'     => ['shopify'],
                    'logVars'        => ['*'],//不记录PHP全局变量$_POST等
                    'logFile'        => '@runtime/logs/shopify.log',
//                    'exportInterval' => 1,//在导出消息之前应该累积多少条消息
                ],

                //以邮件的方式记录,这种方式后面还需设置邮箱的账号密码和host
                [
                    'class' => 'yii\log\EmailTarget',
                    'levels' => ['info'],
                    'categories' => ['shopify'],
                    'logVars'        => ['*'],//不记录PHP全局变量$_POST等
                    'message' => [
                        'from' => ['[email protected]'],
                        'to' => ['[email protected]', '[email protected]'],
                        'subject' => 'email subject',
                    ],
                ],
            ],
        ],

        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => false,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.exmail.qq.com',  //每种邮箱的host配置不一样
                'username' => '[email protected]',
                'password' => 'Z22',
                'port' => '25',
                'encryption' => 'tls',

            ],
]

调用

\Yii::info("zzcchh_test_write_info",'shopify');

记录结果

[zenua@localhost logs]$ cat shopify.log 
2018-10-18 14:09:45 [-][-][-][info][shopify] zzcchh_test_write_info

猜你喜欢

转载自blog.csdn.net/zchqq/article/details/83145838