*/
namespace Friendica\Core;
-use Friendica\BaseObject;
-use Friendica\Network\HTTPException\InternalServerErrorException;
-use Friendica\Util\LoggerFactory;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
/**
* @brief Logger functions
*/
-class Logger extends BaseObject
+class Logger
{
/**
* @see Logger::error()
/**
* Sets the default logging handler for Friendica.
- * @todo Can be combined with other handlers too if necessary, could be configurable.
*
* @param LoggerInterface $logger The Logger instance of this Application
- *
- * @throws InternalServerErrorException if the logger factory is incompatible to this logger
*/
- public static function setLogger($logger)
+ public static function init(LoggerInterface $logger)
{
- $debugging = Config::get('system', 'debugging');
- $logfile = Config::get('system', 'logfile');
- $loglevel = intval(Config::get('system', 'loglevel'));
-
- if (!$debugging || !$logfile) {
- return;
- }
-
- $level = self::mapPSR3Level($loglevel);
- LoggerFactory::addStreamHandler($logger, $logfile, $level);
-
self::$logger = $logger;
+ }
- $logfile = Config::get('system', 'dlogfile');
-
- if (!$logfile) {
- return;
- }
-
- $developIp = Config::get('system', 'dlogip');
-
- self::$devLogger = LoggerFactory::createDev('develop', $developIp);
- LoggerFactory::addStreamHandler(self::$devLogger, $logfile, LogLevel::DEBUG);
+ /**
+ * Sets the default dev-logging handler for Friendica.
+ *
+ * @param LoggerInterface $logger The Logger instance of this Application
+ */
+ public static function setDevLogger(LoggerInterface $logger)
+ {
+ self::$devLogger = $logger;
}
/**
* System is unusable.
+ *
* @see LoggerInterface::emergency()
*
* @param string $message
* @param array $context
*
* @return void
- *
+ * @throws \Exception
*/
public static function emergency($message, $context = [])
{
- if (!isset(self::$logger)) {
- return;
- }
-
- $stamp1 = microtime(true);
self::$logger->emergency($message, $context);
- self::getApp()->saveTimestamp($stamp1, 'file');
}
/**
* @param array $context
*
* @return void
- *
+ * @throws \Exception
*/
public static function alert($message, $context = [])
{
- if (!isset(self::$logger)) {
- return;
- }
-
- $stamp1 = microtime(true);
self::$logger->alert($message, $context);
- self::getApp()->saveTimestamp($stamp1, 'file');
}
/**
* @param array $context
*
* @return void
- *
+ * @throws \Exception
*/
public static function critical($message, $context = [])
{
- if (!isset(self::$logger)) {
- return;
- }
-
- $stamp1 = microtime(true);
self::$logger->critical($message, $context);
- self::getApp()->saveTimestamp($stamp1, 'file');
}
/**
* @param array $context
*
* @return void
- *
+ * @throws \Exception
*/
public static function error($message, $context = [])
{
- if (!isset(self::$logger)) {
- echo "not set!?\n";
- return;
- }
-
- $stamp1 = microtime(true);
self::$logger->error($message, $context);
- self::getApp()->saveTimestamp($stamp1, 'file');
}
/**
* @param array $context
*
* @return void
- *
+ * @throws \Exception
*/
public static function warning($message, $context = [])
{
- if (!isset(self::$logger)) {
- return;
- }
-
- $stamp1 = microtime(true);
self::$logger->warning($message, $context);
- self::getApp()->saveTimestamp($stamp1, 'file');
}
/**
* @param array $context
*
* @return void
- *
+ * @throws \Exception
*/
public static function notice($message, $context = [])
{
- if (!isset(self::$logger)) {
- return;
- }
-
- $stamp1 = microtime(true);
self::$logger->notice($message, $context);
- self::getApp()->saveTimestamp($stamp1, 'file');
}
/**
* @param array $context
*
* @return void
- *
+ * @throws \Exception
*/
public static function info($message, $context = [])
{
- if (!isset(self::$logger)) {
- return;
- }
-
- $stamp1 = microtime(true);
self::$logger->info($message, $context);
- self::getApp()->saveTimestamp($stamp1, 'file');
}
/**
* @param array $context
*
* @return void
+ * @throws \Exception
*/
public static function debug($message, $context = [])
{
- if (!isset(self::$logger)) {
- return;
- }
-
- $stamp1 = microtime(true);
self::$logger->debug($message, $context);
- self::getApp()->saveTimestamp($stamp1, 'file');
}
- /**
- * @brief Logs the given message at the given log level
- *
- * @param string $msg
- * @param int $level
+ /**
+ * @brief Logs the given message at the given log level
+ *
+ * @param string $msg
+ * @param string $level
*
+ * @throws \Exception
* @deprecated since 2019.03 Use Logger::debug() Logger::info() , ... instead
- */
- public static function log($msg, $level = LogLevel::NOTICE)
- {
- if (!isset(self::$logger)) {
- return;
- }
-
- $stamp1 = microtime(true);
+ */
+ public static function log($msg, $level = LogLevel::INFO)
+ {
self::$logger->log($level, $msg);
- self::getApp()->saveTimestamp($stamp1, "file");
- }
+ }
- /**
- * @brief An alternative logger for development.
- * Works largely as log() but allows developers
- * to isolate particular elements they are targetting
- * personally without background noise
- *
- * @param string $msg
+ /**
+ * @brief An alternative logger for development.
+ * Works largely as log() but allows developers
+ * to isolate particular elements they are targetting
+ * personally without background noise
+ *
+ * @param string $msg
* @param string $level
- */
- public static function devLog($msg, $level = LogLevel::DEBUG)
- {
- if (!isset(self::$logger)) {
+ * @throws \Exception
+ */
+ public static function devLog($msg, $level = LogLevel::DEBUG)
+ {
+ if (!isset(self::$devLogger)) {
return;
}
- $stamp1 = microtime(true);
- self::$devLogger->log($level, $msg);
- self::getApp()->saveTimestamp($stamp1, "file");
- }
+ self::$devLogger->log($level, $msg);
+ }
}