AsyncFileTarget.php 733 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace common\components;
  3. use Yii;
  4. use yii\log\FileTarget;
  5. class AsyncFileTarget extends FileTarget
  6. {
  7. /**
  8. * 获取日志文件路径(异步专用能够自动获取当前日期)
  9. * @return string
  10. */
  11. public function getLogFile(){
  12. $logDir = dirname($this->logFile);
  13. return Yii::getAlias($logDir).DIRECTORY_SEPARATOR.'async_'.date('Ymd', time()).'.log';
  14. }
  15. /**
  16. * 重写输出函数,每次输出之前,重新获取一次当前日期的日志文件名
  17. * @throws \yii\base\InvalidConfigException
  18. * @throws \yii\log\LogRuntimeException
  19. */
  20. public function export()
  21. {
  22. $this->logFile = $this->getLogFile();
  23. parent::export();
  24. }
  25. }