yii 2ログ使用

2788 ワード

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