标签:target data- err test 布局 swift .com charset php
今天试着把yii2 的日志,如果发送邮件的形式实现,具体实现如下
lnmp php5.6, mysql5.5, lnmp1.2
yii2-advanced
‘mailer‘ => require_once ‘../config/mail.php‘, ‘log‘ => require_once ‘../config/log.php‘,
<?php return [ ‘class‘ => ‘yii\swiftmailer\Mailer‘, ‘viewPath‘ => ‘@common/mail‘, ‘useFileTransport‘ => false, ‘transport‘ => [ ‘class‘ => ‘Swift_SmtpTransport‘, ‘host‘ => ‘smtp.163.com‘, ‘username‘ => ‘**@163.com‘, ‘password‘ => ‘****‘, ‘port‘ => ‘25‘, ‘encryption‘ => ‘tls‘, ], ‘messageConfig‘=>[ ‘charset‘=>‘UTF-8‘, ‘from‘=>[‘zeopean@163.com‘=>‘zeopean‘] ], ];
<?php return [ ‘traceLevel‘ => YII_DEBUG ? 3 : 0, ‘targets‘ => [ [ ‘class‘ => ‘yii\log\EmailTarget‘, ‘levels‘ => [‘error‘,‘info‘], ‘categories‘ => [‘email_log‘], #该email_log 会在日志方法使用时使用到 ‘message‘ => [ ‘from‘ => [‘**@163.com‘], ‘to‘ => [‘**@qq.com‘], ‘subject‘ => ‘Database errors at example.com‘, ], ], [ ‘class‘ => ‘yii\log\FileTarget‘, ‘levels‘ => [‘error‘, ‘warning‘], ], ], ];
#(frontend/config/routes.php) return [‘GET log-test‘ => ‘demo/log-test‘];
<?php namespace frontend\controllers; use Yii; use yii\debug\models\search\Log; use yii\log\EmailTarget; use yii\web\Controller; /** * Site controller */ class DemoController extends Controller{ public $layout = false; //不使用布局 public $enableCsrfValidation=false; /** * ====================================================================== * 测试日志生成 - 发送邮件 */ public function actionLogTest() { Yii::info("logging info", ‘email_log‘); } }
ok,运行后,邮件便可以收到了。至于其他的日志模式,就需要按照实际的业务来进行了。
标签:target data- err test 布局 swift .com charset php
原文地址:http://www.cnblogs.com/zeopean/p/6023615.html