BaseLog.php 955 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2018/11/20
  6. * Time: 3:32 PM
  7. */
  8. namespace app\framework\Log;
  9. use Monolog\Formatter\LineFormatter;
  10. use Monolog\Handler\RotatingFileHandler;
  11. use Monolog\Logger;
  12. use Illuminate\Log\Writer;
  13. abstract class BaseLog
  14. {
  15. protected $logDir = '';
  16. protected $days = 7;
  17. /**
  18. * @var Writer;
  19. */
  20. protected $log;
  21. public function __construct()
  22. {
  23. $this->log = new \Illuminate\Log\Logger(new Logger(config('app.env')));
  24. // $this->log->useDailyFiles(storage_path() . '/'.$this->logDir, $this->days);
  25. $this->log->getLogger()->pushHandler(
  26. $handler = new RotatingFileHandler(storage_path() . '/'.$this->logDir, $this->days)
  27. );
  28. $handler->setFormatter(new LineFormatter(null,null,true,true));
  29. }
  30. abstract public function add($message, array $content = []);
  31. public function getLogger(){
  32. return $this->log;
  33. }
  34. }