1 | <?php |
||
23 | trait LoggerTrait |
||
24 | { |
||
25 | private static $logTargetSet = false; |
||
26 | |||
27 | /** |
||
28 | * The log file name |
||
29 | * |
||
30 | * @return string |
||
31 | */ |
||
32 | abstract protected static function getLogFileName(): string; |
||
33 | |||
34 | /** |
||
35 | * @inheritdoc |
||
36 | */ |
||
37 | protected static function isDebugModeEnabled() |
||
41 | |||
42 | /** |
||
43 | * The log categories |
||
44 | * |
||
45 | * @return string |
||
46 | */ |
||
47 | protected static function getLogId(): string |
||
51 | |||
52 | /** |
||
53 | * The log categories |
||
54 | * |
||
55 | * @return array |
||
56 | */ |
||
57 | protected static function getLogCategories(): array |
||
62 | |||
63 | /** |
||
64 | * @return string |
||
65 | */ |
||
66 | public static function getLogFile(): string |
||
70 | |||
71 | /** |
||
72 | * @return Logger |
||
73 | */ |
||
74 | public static function getLogger(): Logger |
||
84 | |||
85 | /** |
||
86 | * @noinspection PhpDocMissingThrowsInspection |
||
87 | * @return FileTarget |
||
88 | */ |
||
89 | protected static function createLoggerFileTarget(): FileTarget |
||
97 | |||
98 | /** |
||
99 | * Adds the file target logger |
||
100 | */ |
||
101 | protected static function addLoggerFileTarget() |
||
105 | |||
106 | /** |
||
107 | * @return array |
||
108 | */ |
||
109 | protected static function loggerFileTarget() |
||
126 | |||
127 | /** |
||
128 | * @param string $fileName |
||
129 | * @return string |
||
130 | */ |
||
131 | private static function prepLogFileName(string $fileName): string |
||
137 | |||
138 | /** |
||
139 | * Logs a debug message. |
||
140 | * Trace messages are logged mainly for development purpose to see |
||
141 | * the execution work flow of some code. This method will only log |
||
142 | * a message when the application is in debug mode. |
||
143 | * @param string|array $message the message to be logged. This can be a simple string or a more |
||
144 | * complex data structure, such as array. |
||
145 | * @param string $category the category of the message. |
||
146 | * @since 2.0.14 |
||
147 | */ |
||
148 | public static function debug($message, $category = 'general') |
||
152 | |||
153 | /** |
||
154 | * Logs an error message. |
||
155 | * An error message is typically logged when an unrecoverable error occurs |
||
156 | * during the execution of an application. |
||
157 | * @param string|array $message the message to be logged. This can be a simple string or a more |
||
158 | * complex data structure, such as array. |
||
159 | * @param string $category the category of the message. |
||
160 | */ |
||
161 | public static function error($message, $category = 'general') |
||
165 | |||
166 | /** |
||
167 | * Logs a warning message. |
||
168 | * A warning message is typically logged when an error occurs while the execution |
||
169 | * can still continue. |
||
170 | * @param string|array $message the message to be logged. This can be a simple string or a more |
||
171 | * complex data structure, such as array. |
||
172 | * @param string $category the category of the message. |
||
173 | */ |
||
174 | public static function warning($message, $category = 'general') |
||
178 | |||
179 | /** |
||
180 | * Logs an informative message. |
||
181 | * An informative message is typically logged by an application to keep record of |
||
182 | * something important (e.g. an administrator logs in). |
||
183 | * @param string|array $message the message to be logged. This can be a simple string or a more |
||
184 | * complex data structure, such as array. |
||
185 | * @param string $category the category of the message. |
||
186 | */ |
||
187 | public static function info($message, $category = 'general') |
||
191 | } |
||
192 |
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: