@@ -23,20 +23,34 @@ protected function _echoStderr(string $message): void
23
23
}
24
24
25
25
/**
26
- * Send some info to debug stream .
26
+ * Logs with an arbitrary level .
27
27
*
28
- * @param bool|string $message
29
- * @param array<mixed> $context
28
+ * @param mixed $level
29
+ * @param string|\Stringable $message
30
+ * @param array<mixed> $context
31
+ */
32
+ public function log ($ level , $ message , array $ context = []): void
33
+ {
34
+ if (TraitUtil::hasAppScopeTrait ($ this ) && $ this ->issetApp () && $ this ->getApp ()->logger instanceof \Psr \Log \LoggerInterface) {
35
+ $ this ->getApp ()->logger ->log ($ level , $ message , $ context );
36
+ } else {
37
+ $ this ->_echoStderr ($ message . "\n" );
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Detailed debug information.
30
43
*
31
- * @return $this
44
+ * @param bool|string|\Stringable $message
45
+ * @param array<mixed> $context
32
46
*/
33
- public function debug ($ message = true , array $ context = [])
47
+ public function debug ($ message , array $ context = []): void
34
48
{
35
49
// using this to switch on/off the debug for this object
36
50
if (is_bool ($ message )) {
37
51
$ this ->debug = $ message ;
38
52
39
- return $ this ;
53
+ return ;
40
54
}
41
55
42
56
// if debug is enabled, then log it
@@ -46,28 +60,6 @@ public function debug($message = true, array $context = [])
46
60
}
47
61
$ this ->log (LogLevel::DEBUG , $ message , $ context );
48
62
}
49
-
50
- return $ this ;
51
- }
52
-
53
- /**
54
- * Output log message.
55
- *
56
- * @param mixed $level
57
- * @param string $message
58
- * @param array<mixed> $context
59
- *
60
- * @return $this
61
- */
62
- public function log ($ level , $ message , array $ context = [])
63
- {
64
- if (TraitUtil::hasAppScopeTrait ($ this ) && $ this ->issetApp () && $ this ->getApp ()->logger instanceof \Psr \Log \LoggerInterface) {
65
- $ this ->getApp ()->logger ->log ($ level , $ message , $ context );
66
- } else {
67
- $ this ->_echoStderr ($ message . "\n" );
68
- }
69
-
70
- return $ this ;
71
63
}
72
64
73
65
/**
@@ -79,7 +71,7 @@ public function log($level, $message, array $context = [])
79
71
* Place debugTraceChange inside your hook and give unique $trace identifier. If the method
80
72
* is invoked through different call paths, this debug info will be logged.
81
73
*
82
- * Do not leave this method in production code !!!
74
+ * Do not use this method in production code !!!
83
75
*/
84
76
public function debugTraceChange (string $ trace = 'default ' ): void
85
77
{
@@ -94,7 +86,7 @@ public function debugTraceChange(string $trace = 'default'): void
94
86
$ d1 = array_diff ($ this ->_previousTrace [$ trace ], $ bt );
95
87
$ d2 = array_diff ($ bt , $ this ->_previousTrace [$ trace ]);
96
88
97
- $ this ->log (' debug ' , 'Call path for ' . $ trace . ' has diverged (was ' . implode (', ' , $ d1 ) . ', now ' . implode (', ' , $ d2 ) . ") \n" );
89
+ $ this ->log (LogLevel:: DEBUG , 'Call path for ' . $ trace . ' has diverged (was ' . implode (', ' , $ d1 ) . ', now ' . implode (', ' , $ d2 ) . ") \n" );
98
90
}
99
91
100
92
$ this ->_previousTrace [$ trace ] = $ bt ;
@@ -103,14 +95,12 @@ public function debugTraceChange(string $trace = 'default'): void
103
95
/**
104
96
* System is unusable.
105
97
*
106
- * @param string $message
107
- * @param array<mixed> $context
108
- *
109
- * @return $this
98
+ * @param string|\Stringable $message
99
+ * @param array<mixed> $context
110
100
*/
111
- public function emergency ($ message , array $ context = [])
101
+ public function emergency ($ message , array $ context = []): void
112
102
{
113
- return $ this ->log (LogLevel::EMERGENCY , $ message , $ context );
103
+ $ this ->log (LogLevel::EMERGENCY , $ message , $ context );
114
104
}
115
105
116
106
/**
@@ -119,43 +109,37 @@ public function emergency($message, array $context = [])
119
109
* Example: Entire website down, database unavailable, etc. This should
120
110
* trigger the SMS alerts and wake you up.
121
111
*
122
- * @param string $message
123
- * @param array<mixed> $context
124
- *
125
- * @return $this
112
+ * @param string|\Stringable $message
113
+ * @param array<mixed> $context
126
114
*/
127
- public function alert ($ message , array $ context = [])
115
+ public function alert ($ message , array $ context = []): void
128
116
{
129
- return $ this ->log (LogLevel::ALERT , $ message , $ context );
117
+ $ this ->log (LogLevel::ALERT , $ message , $ context );
130
118
}
131
119
132
120
/**
133
121
* Critical conditions.
134
122
*
135
123
* Example: Application component unavailable, unexpected exception.
136
124
*
137
- * @param string $message
138
- * @param array<mixed> $context
139
- *
140
- * @return $this
125
+ * @param string|\Stringable $message
126
+ * @param array<mixed> $context
141
127
*/
142
- public function critical ($ message , array $ context = [])
128
+ public function critical ($ message , array $ context = []): void
143
129
{
144
- return $ this ->log (LogLevel::CRITICAL , $ message , $ context );
130
+ $ this ->log (LogLevel::CRITICAL , $ message , $ context );
145
131
}
146
132
147
133
/**
148
134
* Runtime errors that do not require immediate action but should typically
149
135
* be logged and monitored.
150
136
*
151
- * @param string $message
152
- * @param array<mixed> $context
153
- *
154
- * @return $this
137
+ * @param string|\Stringable $message
138
+ * @param array<mixed> $context
155
139
*/
156
- public function error ($ message , array $ context = [])
140
+ public function error ($ message , array $ context = []): void
157
141
{
158
- return $ this ->log (LogLevel::ERROR , $ message , $ context );
142
+ $ this ->log (LogLevel::ERROR , $ message , $ context );
159
143
}
160
144
161
145
/**
@@ -164,41 +148,35 @@ public function error($message, array $context = [])
164
148
* Example: Use of deprecated APIs, poor use of an API, undesirable things
165
149
* that are not necessarily wrong.
166
150
*
167
- * @param string $message
168
- * @param array<mixed> $context
169
- *
170
- * @return $this
151
+ * @param string|\Stringable $message
152
+ * @param array<mixed> $context
171
153
*/
172
- public function warning ($ message , array $ context = [])
154
+ public function warning ($ message , array $ context = []): void
173
155
{
174
- return $ this ->log (LogLevel::WARNING , $ message , $ context );
156
+ $ this ->log (LogLevel::WARNING , $ message , $ context );
175
157
}
176
158
177
159
/**
178
160
* Normal but significant events.
179
161
*
180
- * @param string $message
181
- * @param array<mixed> $context
182
- *
183
- * @return $this
162
+ * @param string|\Stringable $message
163
+ * @param array<mixed> $context
184
164
*/
185
- public function notice ($ message , array $ context = [])
165
+ public function notice ($ message , array $ context = []): void
186
166
{
187
- return $ this ->log (LogLevel::NOTICE , $ message , $ context );
167
+ $ this ->log (LogLevel::NOTICE , $ message , $ context );
188
168
}
189
169
190
170
/**
191
171
* Interesting events.
192
172
*
193
173
* Example: User logs in, SQL logs.
194
174
*
195
- * @param string $message
196
- * @param array<mixed> $context
197
- *
198
- * @return $this
175
+ * @param string|\Stringable $message
176
+ * @param array<mixed> $context
199
177
*/
200
- public function info ($ message , array $ context = [])
178
+ public function info ($ message , array $ context = []): void
201
179
{
202
- return $ this ->log (LogLevel::INFO , $ message , $ context );
180
+ $ this ->log (LogLevel::INFO , $ message , $ context );
203
181
}
204
182
}
0 commit comments