@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\Database\Connection; |
16 | 16 | use chillerlan\Logger\LogOptions; |
17 | 17 | |
18 | -class DatabaseLog extends LogOutputAbstract{ |
|
18 | +class DatabaseLog extends LogOutputAbstract { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var \chillerlan\Database\Connection |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param \chillerlan\Logger\LogOptions $options |
30 | 30 | * @param \chillerlan\Database\Connection $db |
31 | 31 | */ |
32 | - public function __construct(LogOptions $options, Connection $db){ |
|
32 | + public function __construct(LogOptions $options, Connection $db) { |
|
33 | 33 | $this->options = $options; |
34 | 34 | $this->db = $db; |
35 | 35 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * @inheritdoc |
41 | 41 | */ |
42 | - protected function __log(string $level, string $message, array $context = []){ |
|
42 | + protected function __log(string $level, string $message, array $context = []) { |
|
43 | 43 | |
44 | 44 | // TODO: $context, tests |
45 | 45 | $this->db->insert |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * |
20 | 20 | */ |
21 | -abstract class LogOutputAbstract implements LogOutputInterface{ |
|
21 | +abstract class LogOutputAbstract implements LogOutputInterface { |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * @var \chillerlan\Logger\LogOptions |
@@ -30,14 +30,14 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @param \chillerlan\Traits\ContainerInterface|null $options |
32 | 32 | */ |
33 | - public function __construct(ContainerInterface $options = null){ |
|
33 | + public function __construct(ContainerInterface $options = null) { |
|
34 | 34 | $this->options = $options ?? new LogOptions; |
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
38 | 38 | * @inheritdoc |
39 | 39 | */ |
40 | - public function __destruct(){ |
|
40 | + public function __destruct() { |
|
41 | 41 | $this->close(); |
42 | 42 | } |
43 | 43 | |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * @inheritdoc |
62 | 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))){ |
|
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 | 65 | $this->__log($level, $message, $context); |
66 | 66 | } |
67 | 67 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @return string |
75 | 75 | */ |
76 | - protected function message(string $level, string $message, array $context = null){ |
|
76 | + protected function message(string $level, string $message, array $context = null) { |
|
77 | 77 | return sprintf($this->options->consoleFormat, date($this->options->consoleDateFormat), $level, $message).PHP_EOL; |
78 | 78 | } |
79 | 79 |
@@ -14,12 +14,12 @@ |
||
14 | 14 | |
15 | 15 | /** |
16 | 16 | */ |
17 | -class ConsoleLog extends LogOutputAbstract{ |
|
17 | +class ConsoleLog extends LogOutputAbstract { |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @inheritdoc |
21 | 21 | */ |
22 | - protected function __log(string $level, string $message, array $context = null){ |
|
22 | + protected function __log(string $level, string $message, array $context = null) { |
|
23 | 23 | echo $this->message($level, $message, $context); |
24 | 24 | } |
25 | 25 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | |
18 | 18 | /** |
19 | 19 | */ |
20 | -class Logfile extends LogOutputAbstract{ |
|
20 | +class Logfile extends LogOutputAbstract { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @var bool|resource |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @throws \chillerlan\Logger\LogException |
33 | 33 | */ |
34 | - public function __construct(ContainerInterface $options = null){ |
|
34 | + public function __construct(ContainerInterface $options = null) { |
|
35 | 35 | parent::__construct($options); |
36 | 36 | |
37 | - if(!is_writable($this->options->logfileDir)){ |
|
37 | + if (!is_writable($this->options->logfileDir)) { |
|
38 | 38 | throw new LogException('log file directory inaccessible'); |
39 | 39 | } |
40 | 40 | |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | /** |
47 | 47 | * @inheritdoc |
48 | 48 | */ |
49 | - public function __destruct(){ |
|
49 | + public function __destruct() { |
|
50 | 50 | $this->close(); |
51 | 51 | |
52 | - if(gettype($this->fh) === 'resource'){ |
|
52 | + if (gettype($this->fh) === 'resource') { |
|
53 | 53 | fclose($this->fh); |
54 | 54 | } |
55 | 55 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | /** |
58 | 58 | * @inheritdoc |
59 | 59 | */ |
60 | - protected function __log(string $level, string $message, array $context = null){ |
|
60 | + protected function __log(string $level, string $message, array $context = null) { |
|
61 | 61 | fwrite($this->fh, $this->message($level, $message, $context)); |
62 | 62 | } |
63 | 63 |
@@ -23,6 +23,6 @@ |
||
23 | 23 | * @property string $logfileName |
24 | 24 | * @property string $logfileExt |
25 | 25 | */ |
26 | -class LogOptions extends ContainerAbstract{ |
|
26 | +class LogOptions extends ContainerAbstract { |
|
27 | 27 | use LogOptionsTrait; |
28 | 28 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | |
20 | 20 | /** |
21 | 21 | */ |
22 | -class Log implements LoggerInterface{ |
|
22 | +class Log implements LoggerInterface { |
|
23 | 23 | use LoggerTrait; |
24 | 24 | /** |
25 | 25 | * @var \chillerlan\Logger\LogOptions |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * |
36 | 36 | */ |
37 | - public function __destruct(){ |
|
37 | + public function __destruct() { |
|
38 | 38 | $this->close(); |
39 | 39 | } |
40 | 40 | |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function close():Log{ |
47 | 47 | |
48 | - if(!empty($this->logOutputInterfaces)){ |
|
49 | - foreach($this->logOutputInterfaces as $instanceName => $instance){ |
|
48 | + if (!empty($this->logOutputInterfaces)) { |
|
49 | + foreach ($this->logOutputInterfaces as $instanceName => $instance) { |
|
50 | 50 | unset($this->logOutputInterfaces[$instanceName]); |
51 | 51 | } |
52 | 52 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function getInstance(string $instanceName):LogOutputInterface{ |
76 | 76 | |
77 | - if(!array_key_exists($instanceName, $this->logOutputInterfaces)){ |
|
77 | + if (!array_key_exists($instanceName, $this->logOutputInterfaces)) { |
|
78 | 78 | throw new LogException('invalid logger instance: '.$instanceName); |
79 | 79 | } |
80 | 80 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function removeInstance(string $instanceName):Log{ |
91 | 91 | |
92 | - if(!array_key_exists($instanceName, $this->logOutputInterfaces)){ |
|
92 | + if (!array_key_exists($instanceName, $this->logOutputInterfaces)) { |
|
93 | 93 | throw new LogException('invalid logger instance: '.$instanceName); |
94 | 94 | } |
95 | 95 | |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @return void |
111 | 111 | */ |
112 | - public function log($level, $message, array $context = [], string $instance = null){ |
|
112 | + public function log($level, $message, array $context = [], string $instance = null) { |
|
113 | 113 | |
114 | - foreach($this->logOutputInterfaces as $logger){ |
|
114 | + foreach ($this->logOutputInterfaces as $logger) { |
|
115 | 115 | $logger->log($level, $message, $context); |
116 | 116 | } |
117 | 117 |