chillerlan /
php-log
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Class LogOutputAbstract |
||
| 4 | * |
||
| 5 | * @filesource LogOutputAbstract.php |
||
| 6 | * @created 04.01.2018 |
||
| 7 | * @package chillerlan\Logger\Output |
||
| 8 | * @author Smiley <[email protected]> |
||
| 9 | * @copyright 2018 Smiley |
||
| 10 | * @license MIT |
||
| 11 | */ |
||
| 12 | |||
| 13 | namespace chillerlan\Logger\Output; |
||
| 14 | |||
| 15 | use chillerlan\Logger\LogOptions; |
||
| 16 | use chillerlan\Settings\SettingsContainerInterface; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * |
||
| 20 | */ |
||
| 21 | abstract class LogOutputAbstract implements LogOutputInterface{ |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var \chillerlan\Logger\LogOptions |
||
| 25 | */ |
||
| 26 | protected $options; |
||
| 27 | 1 | ||
| 28 | 1 | /** |
|
| 29 | 1 | * LogOutputAbstract constructor. |
|
| 30 | * |
||
| 31 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
||
| 32 | */ |
||
| 33 | public function __construct(SettingsContainerInterface $options = null){ |
||
| 34 | $this->options = $options ?? new LogOptions; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @inheritdoc |
||
| 39 | */ |
||
| 40 | public function __destruct(){ |
||
| 41 | $this->close(); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @inheritdoc |
||
| 46 | */ |
||
| 47 | public function close():LogOutputInterface{ |
||
| 48 | return $this; |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param string $level |
||
| 53 | * @param string $message |
||
| 54 | * @param array $context |
||
| 55 | * |
||
| 56 | * @return mixed |
||
| 57 | */ |
||
| 58 | abstract protected function __log(string $level, string $message, array $context = []); |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @inheritdoc |
||
| 62 | */ |
||
| 63 | public function log(string $level, string $message, array $context = []){ // @todo: loglevel bitmask |
||
| 64 | if((array_key_exists($level, $this::LEVELS) && $this::LEVELS[$level] >= $this::LEVELS[$this->options->minLogLevel]) || (!array_key_exists($level, $this::LEVELS) && !empty($level))){ |
||
| 65 | $this->__log($level, $message, $context); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @param string $level |
||
| 71 | * @param string $message |
||
| 72 | * @param array|null $context |
||
| 73 | * |
||
| 74 | * @return string |
||
| 75 | */ |
||
| 76 | protected function message(string $level, string $message, array $context = null){ |
||
|
0 ignored issues
–
show
|
|||
| 77 | return sprintf($this->options->consoleFormat, date($this->options->consoleDateFormat), $level, $message).PHP_EOL; |
||
| 78 | } |
||
| 79 | |||
| 80 | } |
||
| 81 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.