6262 * MonoLog is an example implementing this interface.
6363 */
6464class Log implements ILogger, IDataLogger {
65- private ?SystemConfig $ config ;
6665 private ?bool $ logConditionSatisfied = null ;
67- private ?Normalizer $ normalizer ;
68- private ?IEventDispatcher $ eventDispatcher ;
66+ private ?IEventDispatcher $ eventDispatcher = null ;
6967
70- /**
71- * @param IWriter $logger The logger that should be used
72- * @param SystemConfig|null $config the system config object
73- * @param Normalizer|null $normalizer
74- * @param IRegistry|null $crashReporters
75- */
7668 public function __construct (
7769 private IWriter $ logger ,
78- SystemConfig $ config = null ,
79- Normalizer $ normalizer = null ,
80- private ?IRegistry $ crashReporters = null
70+ private ? SystemConfig $ config = null ,
71+ private ? Normalizer $ normalizer = null ,
72+ private ?IRegistry $ crashReporters = null
8173 ) {
8274 // FIXME: Add this for backwards compatibility, should be fixed at some point probably
8375 if ($ config === null ) {
84- $ config = \OC ::$ server ->getSystemConfig ();
76+ $ this -> config = \OC ::$ server ->getSystemConfig ();
8577 }
8678
87- $ this ->config = $ config ;
8879 if ($ normalizer === null ) {
8980 $ this ->normalizer = new Normalizer ();
90- } else {
91- $ this ->normalizer = $ normalizer ;
9281 }
93- $ this ->eventDispatcher = null ;
9482 }
9583
96- public function setEventDispatcher (IEventDispatcher $ eventDispatcher ) {
84+ public function setEventDispatcher (IEventDispatcher $ eventDispatcher ): void {
9785 $ this ->eventDispatcher = $ eventDispatcher ;
9886 }
9987
@@ -102,9 +90,8 @@ public function setEventDispatcher(IEventDispatcher $eventDispatcher) {
10290 *
10391 * @param string $message
10492 * @param array $context
105- * @return void
10693 */
107- public function emergency (string $ message , array $ context = []) {
94+ public function emergency (string $ message , array $ context = []): void {
10895 $ this ->log (ILogger::FATAL , $ message , $ context );
10996 }
11097
@@ -116,9 +103,8 @@ public function emergency(string $message, array $context = []) {
116103 *
117104 * @param string $message
118105 * @param array $context
119- * @return void
120106 */
121- public function alert (string $ message , array $ context = []) {
107+ public function alert (string $ message , array $ context = []): void {
122108 $ this ->log (ILogger::ERROR , $ message , $ context );
123109 }
124110
@@ -129,9 +115,8 @@ public function alert(string $message, array $context = []) {
129115 *
130116 * @param string $message
131117 * @param array $context
132- * @return void
133118 */
134- public function critical (string $ message , array $ context = []) {
119+ public function critical (string $ message , array $ context = []): void {
135120 $ this ->log (ILogger::ERROR , $ message , $ context );
136121 }
137122
@@ -141,9 +126,8 @@ public function critical(string $message, array $context = []) {
141126 *
142127 * @param string $message
143128 * @param array $context
144- * @return void
145129 */
146- public function error (string $ message , array $ context = []) {
130+ public function error (string $ message , array $ context = []): void {
147131 $ this ->log (ILogger::ERROR , $ message , $ context );
148132 }
149133
@@ -155,9 +139,8 @@ public function error(string $message, array $context = []) {
155139 *
156140 * @param string $message
157141 * @param array $context
158- * @return void
159142 */
160- public function warning (string $ message , array $ context = []) {
143+ public function warning (string $ message , array $ context = []): void {
161144 $ this ->log (ILogger::WARN , $ message , $ context );
162145 }
163146
@@ -166,9 +149,8 @@ public function warning(string $message, array $context = []) {
166149 *
167150 * @param string $message
168151 * @param array $context
169- * @return void
170152 */
171- public function notice (string $ message , array $ context = []) {
153+ public function notice (string $ message , array $ context = []): void {
172154 $ this ->log (ILogger::INFO , $ message , $ context );
173155 }
174156
@@ -179,9 +161,8 @@ public function notice(string $message, array $context = []) {
179161 *
180162 * @param string $message
181163 * @param array $context
182- * @return void
183164 */
184- public function info (string $ message , array $ context = []) {
165+ public function info (string $ message , array $ context = []): void {
185166 $ this ->log (ILogger::INFO , $ message , $ context );
186167 }
187168
@@ -190,9 +171,8 @@ public function info(string $message, array $context = []) {
190171 *
191172 * @param string $message
192173 * @param array $context
193- * @return void
194174 */
195- public function debug (string $ message , array $ context = []) {
175+ public function debug (string $ message , array $ context = []): void {
196176 $ this ->log (ILogger::DEBUG , $ message , $ context );
197177 }
198178
@@ -203,9 +183,8 @@ public function debug(string $message, array $context = []) {
203183 * @param int $level
204184 * @param string $message
205185 * @param array $context
206- * @return void
207186 */
208- public function log (int $ level , string $ message , array $ context = []) {
187+ public function log (int $ level , string $ message , array $ context = []): void {
209188 $ minLevel = $ this ->getLogLevel ($ context );
210189 if ($ level < $ minLevel && (($ this ->crashReporters ?->hasReporters() ?? false ) === false )) {
211190 return ; // we already know that log will be fully ignored
@@ -247,7 +226,7 @@ public function log(int $level, string $message, array $context = []) {
247226 }
248227 }
249228
250- public function getLogLevel ($ context ) {
229+ public function getLogLevel ($ context ): int {
251230 $ logCondition = $ this ->config ->getValue ('log.condition ' , []);
252231
253232 /**
@@ -297,15 +276,11 @@ public function getLogLevel($context) {
297276 }
298277
299278 if (isset ($ context ['app ' ])) {
300- $ app = $ context ['app ' ];
301-
302279 /**
303280 * check log condition based on the context of each log message
304281 * once this is met -> change the required log level to debug
305282 */
306- if (!empty ($ logCondition )
307- && isset ($ logCondition ['apps ' ])
308- && in_array ($ app , $ logCondition ['apps ' ], true )) {
283+ if (in_array ($ context ['app ' ], $ logCondition ['apps ' ] ?? [], true )) {
309284 return ILogger::DEBUG ;
310285 }
311286 }
@@ -321,7 +296,7 @@ public function getLogLevel($context) {
321296 * @return void
322297 * @since 8.2.0
323298 */
324- public function logException (Throwable $ exception , array $ context = []) {
299+ public function logException (Throwable $ exception , array $ context = []): void {
325300 $ app = $ context ['app ' ] ?? 'no app in context ' ;
326301 $ level = $ context ['level ' ] ?? ILogger::ERROR ;
327302
@@ -396,7 +371,7 @@ public function logData(string $message, array $data, array $context = []): void
396371 * @param string|array $entry
397372 * @param int $level
398373 */
399- protected function writeLog (string $ app , $ entry , int $ level ) {
374+ protected function writeLog (string $ app , $ entry , int $ level ): void {
400375 $ this ->logger ->write ($ app , $ entry , $ level );
401376 }
402377
0 commit comments