美文网首页
yii2日志使用

yii2日志使用

作者: 我的楼兰0909 | 来源:发表于2018-12-13 22:18 被阅读0次
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' => ['gloerver@emailcxs.com'],
                        'to' => ['24253@qq.com', 'ze.h@jinet.com'],
                        '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' => 'zeh@jnet.com',
                '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

相关文章

网友评论

      本文标题:yii2日志使用

      本文链接:https://www.haomeiwen.com/subject/nfcthqtx.html