| Total Complexity | 6 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | class FileLog extends LogOutputAbstract{ |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var bool|resource |
||
| 22 | */ |
||
| 23 | protected $fh; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * FileLog constructor. |
||
| 27 | * |
||
| 28 | * @param \chillerlan\Traits\ImmutableSettingsInterface|null $options |
||
| 29 | * |
||
| 30 | * @throws \chillerlan\Logger\LogException |
||
| 31 | */ |
||
| 32 | public function __construct(ImmutableSettingsInterface $options = null){ |
||
| 33 | parent::__construct($options); |
||
| 34 | |||
| 35 | if(!is_writable($this->options->logfileDir)){ |
||
| 36 | throw new LogException('log file directory inaccessible'); |
||
| 37 | } |
||
| 38 | |||
| 39 | $logfile = $this->options->logfileDir.'/'.$this->options->logfileName.'-'.date('Y-m-d').'.'.$this->options->logfileExt; |
||
| 40 | |||
| 41 | $this->fh = fopen($logfile, 'a+'); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @inheritdoc |
||
| 46 | */ |
||
| 47 | public function __destruct(){ |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @inheritdoc |
||
| 57 | */ |
||
| 58 | protected function __log(string $level, string $message, array $context = null){ |
||
| 59 | fwrite($this->fh, $this->message($level, $message, $context)); |
||
|
|
|||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @inheritdoc |
||
| 64 | */ |
||
| 65 | public function close():LogOutputInterface{ |
||
| 68 | } |
||
| 69 | |||
| 71 |