| 12345678910111213141516171819202122232425262728293031 |
- <?php
- namespace common\components;
- use Yii;
- use yii\log\FileTarget;
- class AsyncFileTarget extends FileTarget
- {
- /**
- * 获取日志文件路径(异步专用能够自动获取当前日期)
- * @return string
- */
- public function getLogFile(){
- $logDir = dirname($this->logFile);
- return Yii::getAlias($logDir).DIRECTORY_SEPARATOR.'async_'.date('Ymd', time()).'.log';
- }
- /**
- * 重写输出函数,每次输出之前,重新获取一次当前日期的日志文件名
- * @throws \yii\base\InvalidConfigException
- * @throws \yii\log\LogRuntimeException
- */
- public function export()
- {
- $this->logFile = $this->getLogFile();
- parent::export();
- }
- }
|