日志使用方式:http://www.yiifans.com/yii2/guide/runtime-logging.html
使用时注意日志的权限
基本配置如下:
[ 'bootstrap' => ['log'], // ensure logger gets loaded before application starts 'components' => [ 'log' => [ 'targets' => [ 'file' => [ 'class' => 'yii\log\FileTarget', //日志处理类 'levels' => ['trace', 'info'], //trace,info 级别的日志写入到文件 'categories' => ['yii\*'], // 指所有以 yii\ 开头的类别 ], 'email' => [ 'class' => 'yii\log\EmailTarget', //日志处理类 'levels' => ['error', 'warning'], //error,warning级别的日志发送邮件 'message' => [ 'to' => ['admin@techbrood.com', 'support@techbrood.com'], 'subject' => 'New example.com log message', ], ], ], ], ], ]
基本使用方法如下:
//还有其他参数,请参考手册或者源码 \Yii::info('Hello, I am a test log message'); \Yii::error('Hello, I am a test log message'); \Yii::trace('Hello, I am a test log message'); \Yii::warning('Hello, I am a test log message');