3 * @file src/Core/Logger.php
5 namespace Friendica\Core;
7 use Psr\Log\LoggerInterface;
11 * @brief Logger functions
16 * @see Logger::error()
18 const WARNING = LogLevel::ERROR;
20 * @see Logger::warning()
22 const INFO = LogLevel::WARNING;
24 * @see Logger::notice()
26 const TRACE = LogLevel::NOTICE;
30 const DEBUG = LogLevel::INFO;
32 * @see Logger::debug()
34 const DATA = LogLevel::DEBUG;
36 * @see Logger::debug()
38 const ALL = LogLevel::DEBUG;
41 * @var array the legacy loglevels
42 * @deprecated 2019.03 use PSR-3 loglevels
43 * @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#5-psrlogloglevel
46 public static $levels = [
47 self::WARNING => 'Warning',
49 self::TRACE => 'Trace',
50 self::DEBUG => 'Debug',
56 * @var LoggerInterface A PSR-3 compliant logger instance
58 private static $logger;
61 * @var LoggerInterface A PSR-3 compliant logger instance for developing only
63 private static $devLogger;
66 * Sets the default logging handler for Friendica.
68 * @param LoggerInterface $logger The Logger instance of this Application
70 public static function init(LoggerInterface $logger)
72 self::$logger = $logger;
76 * Sets the default dev-logging handler for Friendica.
78 * @param LoggerInterface $logger The Logger instance of this Application
80 public static function setDevLogger(LoggerInterface $logger)
82 self::$devLogger = $logger;
88 * @see LoggerInterface::emergency()
90 * @param string $message
91 * @param array $context
96 public static function emergency($message, $context = [])
98 self::$logger->emergency($message, $context);
102 * Action must be taken immediately.
103 * @see LoggerInterface::alert()
105 * Example: Entire website down, database unavailable, etc. This should
106 * trigger the SMS alerts and wake you up.
108 * @param string $message
109 * @param array $context
114 public static function alert($message, $context = [])
116 self::$logger->alert($message, $context);
120 * Critical conditions.
121 * @see LoggerInterface::critical()
123 * Example: Application component unavailable, unexpected exception.
125 * @param string $message
126 * @param array $context
131 public static function critical($message, $context = [])
133 self::$logger->critical($message, $context);
137 * Runtime errors that do not require immediate action but should typically
138 * be logged and monitored.
139 * @see LoggerInterface::error()
141 * @param string $message
142 * @param array $context
147 public static function error($message, $context = [])
149 self::$logger->error($message, $context);
153 * Exceptional occurrences that are not errors.
154 * @see LoggerInterface::warning()
156 * Example: Use of deprecated APIs, poor use of an API, undesirable things
157 * that are not necessarily wrong.
159 * @param string $message
160 * @param array $context
165 public static function warning($message, $context = [])
167 self::$logger->warning($message, $context);
171 * Normal but significant events.
172 * @see LoggerInterface::notice()
174 * @param string $message
175 * @param array $context
180 public static function notice($message, $context = [])
182 self::$logger->notice($message, $context);
186 * Interesting events.
187 * @see LoggerInterface::info()
189 * Example: User logs in, SQL logs.
191 * @param string $message
192 * @param array $context
197 public static function info($message, $context = [])
199 self::$logger->info($message, $context);
203 * Detailed debug information.
204 * @see LoggerInterface::debug()
206 * @param string $message
207 * @param array $context
212 public static function debug($message, $context = [])
214 self::$logger->debug($message, $context);
218 * @brief Logs the given message at the given log level
221 * @param string $level
224 * @deprecated since 2019.03 Use Logger::debug() Logger::info() , ... instead
226 public static function log($msg, $level = LogLevel::INFO)
228 self::$logger->log($level, $msg);
232 * @brief An alternative logger for development.
233 * Works largely as log() but allows developers
234 * to isolate particular elements they are targetting
235 * personally without background noise
238 * @param string $level
241 public static function devLog($msg, $level = LogLevel::DEBUG)
243 if (!isset(self::$devLogger)) {
247 self::$devLogger->log($level, $msg);