3 * @file src/Core/Logger.php
5 namespace Friendica\Core;
8 use Friendica\Util\Logger\WorkerLogger;
9 use Psr\Log\LoggerInterface;
18 * @see Logger::error()
19 * @deprecated since 2019.01
21 const WARNING = LogLevel::ERROR;
23 * @see Logger::warning()
24 * @deprecated since 2019.01
26 const INFO = LogLevel::WARNING;
28 * @see Logger::notice()
29 * @deprecated since 2019.01
31 const TRACE = LogLevel::NOTICE;
34 * @deprecated since 2019.01
36 const DEBUG = LogLevel::INFO;
38 * @see Logger::debug()
39 * @deprecated since 2019.01
41 const DATA = LogLevel::DEBUG;
43 * @see Logger::debug()
44 * @deprecated since 2019.01
46 const ALL = LogLevel::DEBUG;
49 * @var LoggerInterface The default Logger type
51 const TYPE_LOGGER = LoggerInterface::class;
53 * @var WorkerLogger A specific worker logger type, which can be anabled
55 const TYPE_WORKER = WorkerLogger::class;
57 * @var LoggerInterface The current logger type
59 private static $type = self::TYPE_LOGGER;
62 * @var array the legacy loglevels
63 * @deprecated 2019.03 use PSR-3 loglevels
64 * @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#5-psrlogloglevel
67 public static $levels = [
68 self::WARNING => 'Warning',
70 self::TRACE => 'Trace',
71 self::DEBUG => 'Debug',
76 * @return LoggerInterface
78 private static function getWorker()
80 if (self::$type === self::TYPE_LOGGER) {
83 return DI::workerLogger();
88 * Enable additional logging for worker usage
90 * @param string $functionName The worker function, which got called
92 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
94 public static function enableWorker(string $functionName)
96 self::$type = self::TYPE_WORKER;
97 self::getWorker()->setFunctionName($functionName);
101 * Disable additional logging for worker usage
103 public static function disableWorker()
105 self::$type = self::TYPE_LOGGER;
109 * System is unusable.
111 * @see LoggerInterface::emergency()
113 * @param string $message
114 * @param array $context
119 public static function emergency($message, $context = [])
121 self::getWorker()->emergency($message, $context);
125 * Action must be taken immediately.
126 * @see LoggerInterface::alert()
128 * Example: Entire website down, database unavailable, etc. This should
129 * trigger the SMS alerts and wake you up.
131 * @param string $message
132 * @param array $context
137 public static function alert($message, $context = [])
139 self::getWorker()->alert($message, $context);
143 * Critical conditions.
144 * @see LoggerInterface::critical()
146 * Example: Application component unavailable, unexpected exception.
148 * @param string $message
149 * @param array $context
154 public static function critical($message, $context = [])
156 self::getWorker()->critical($message, $context);
160 * Runtime errors that do not require immediate action but should typically
161 * be logged and monitored.
162 * @see LoggerInterface::error()
164 * @param string $message
165 * @param array $context
170 public static function error($message, $context = [])
172 self::getWorker()->error($message, $context);
176 * Exceptional occurrences that are not errors.
177 * @see LoggerInterface::warning()
179 * Example: Use of deprecated APIs, poor use of an API, undesirable things
180 * that are not necessarily wrong.
182 * @param string $message
183 * @param array $context
188 public static function warning($message, $context = [])
190 self::getWorker()->warning($message, $context);
194 * Normal but significant events.
195 * @see LoggerInterface::notice()
197 * @param string $message
198 * @param array $context
203 public static function notice($message, $context = [])
205 self::getWorker()->notice($message, $context);
209 * Interesting events.
210 * @see LoggerInterface::info()
212 * Example: User logs in, SQL logs.
214 * @param string $message
215 * @param array $context
220 public static function info($message, $context = [])
222 self::getWorker()->info($message, $context);
226 * Detailed debug information.
227 * @see LoggerInterface::debug()
229 * @param string $message
230 * @param array $context
235 public static function debug($message, $context = [])
237 self::getWorker()->debug($message, $context);
241 * Logs the given message at the given log level
244 * @param string $level
247 * @deprecated since 2019.03 Use Logger::debug() Logger::info() , ... instead
249 public static function log($msg, $level = LogLevel::INFO)
251 self::getWorker()->log($level, $msg);
255 * An alternative logger for development.
257 * Works largely as log() but allows developers
258 * to isolate particular elements they are targetting
259 * personally without background noise
262 * @param string $level
265 public static function devLog($msg, $level = LogLevel::DEBUG)
267 DI::devLogger()->log($level, $msg);