3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Core;
25 use Friendica\Util\Logger\WorkerLogger;
26 use Psr\Log\LoggerInterface;
35 * @see Logger::error()
36 * @deprecated since 2019.01
38 const WARNING = LogLevel::ERROR;
40 * @see Logger::warning()
41 * @deprecated since 2019.01
43 const INFO = LogLevel::WARNING;
45 * @see Logger::notice()
46 * @deprecated since 2019.01
48 const TRACE = LogLevel::NOTICE;
51 * @deprecated since 2019.01
53 const DEBUG = LogLevel::INFO;
55 * @see Logger::debug()
56 * @deprecated since 2019.01
58 const DATA = LogLevel::DEBUG;
60 * @see Logger::debug()
61 * @deprecated since 2019.01
63 const ALL = LogLevel::DEBUG;
66 * @var LoggerInterface The default Logger type
68 const TYPE_LOGGER = LoggerInterface::class;
70 * @var WorkerLogger A specific worker logger type, which can be anabled
72 const TYPE_WORKER = WorkerLogger::class;
74 * @var LoggerInterface The current logger type
76 private static $type = self::TYPE_LOGGER;
79 * @var array the legacy loglevels
80 * @deprecated 2019.03 use PSR-3 loglevels
81 * @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#5-psrlogloglevel
84 public static $levels = [
85 self::WARNING => 'Warning',
87 self::TRACE => 'Trace',
88 self::DEBUG => 'Debug',
93 * @return LoggerInterface
95 private static function getWorker()
97 if (self::$type === self::TYPE_LOGGER) {
100 return DI::workerLogger();
105 * Enable additional logging for worker usage
107 * @param string $functionName The worker function, which got called
109 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
111 public static function enableWorker(string $functionName)
113 self::$type = self::TYPE_WORKER;
114 self::getWorker()->setFunctionName($functionName);
118 * Disable additional logging for worker usage
120 public static function disableWorker()
122 self::$type = self::TYPE_LOGGER;
126 * System is unusable.
128 * @see LoggerInterface::emergency()
130 * @param string $message
131 * @param array $context
136 public static function emergency($message, $context = [])
138 self::getWorker()->emergency($message, $context);
142 * Action must be taken immediately.
143 * @see LoggerInterface::alert()
145 * Example: Entire website down, database unavailable, etc. This should
146 * trigger the SMS alerts and wake you up.
148 * @param string $message
149 * @param array $context
154 public static function alert($message, $context = [])
156 self::getWorker()->alert($message, $context);
160 * Critical conditions.
161 * @see LoggerInterface::critical()
163 * Example: Application component unavailable, unexpected exception.
165 * @param string $message
166 * @param array $context
171 public static function critical($message, $context = [])
173 self::getWorker()->critical($message, $context);
177 * Runtime errors that do not require immediate action but should typically
178 * be logged and monitored.
179 * @see LoggerInterface::error()
181 * @param string $message
182 * @param array $context
187 public static function error($message, $context = [])
189 self::getWorker()->error($message, $context);
193 * Exceptional occurrences that are not errors.
194 * @see LoggerInterface::warning()
196 * Example: Use of deprecated APIs, poor use of an API, undesirable things
197 * that are not necessarily wrong.
199 * @param string $message
200 * @param array $context
205 public static function warning($message, $context = [])
207 self::getWorker()->warning($message, $context);
211 * Normal but significant events.
212 * @see LoggerInterface::notice()
214 * @param string $message
215 * @param array $context
220 public static function notice($message, $context = [])
222 self::getWorker()->notice($message, $context);
226 * Interesting events.
227 * @see LoggerInterface::info()
229 * Example: User logs in, SQL logs.
231 * @param string $message
232 * @param array $context
237 public static function info($message, $context = [])
239 self::getWorker()->info($message, $context);
243 * Detailed debug information.
244 * @see LoggerInterface::debug()
246 * @param string $message
247 * @param array $context
252 public static function debug($message, $context = [])
254 self::getWorker()->debug($message, $context);
258 * Logs the given message at the given log level
261 * @param string $level
264 * @deprecated since 2019.03 Use Logger::debug() Logger::info() , ... instead
266 public static function log($msg, $level = LogLevel::INFO)
268 self::getWorker()->log($level, $msg);
272 * An alternative logger for development.
274 * Works largely as log() but allows developers
275 * to isolate particular elements they are targetting
276 * personally without background noise
279 * @param string $level
282 public static function devLog($msg, $level = LogLevel::DEBUG)
284 DI::devLogger()->log($level, $msg);