X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FLogger.php;h=fc2dde1dfe703f3de75e6044cc7fccc8b699e7bd;hb=318a3ca785474fa27fbff9b3ee19fd4c04261ecd;hp=c6b81e0cc993eea1ef1060f75a3f229a291f7212;hpb=6e48df21631f1c616a6c88369677ecf1038f4d1f;p=friendica.git diff --git a/src/Core/Logger.php b/src/Core/Logger.php index c6b81e0cc9..fc2dde1dfe 100644 --- a/src/Core/Logger.php +++ b/src/Core/Logger.php @@ -4,16 +4,13 @@ */ 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() @@ -67,58 +64,38 @@ class Logger extends BaseObject /** * 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'); } /** @@ -132,17 +109,11 @@ class Logger extends BaseObject * @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'); } /** @@ -155,17 +126,11 @@ class Logger extends BaseObject * @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'); } /** @@ -177,18 +142,11 @@ class Logger extends BaseObject * @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'); } /** @@ -202,17 +160,11 @@ class Logger extends BaseObject * @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'); } /** @@ -223,17 +175,11 @@ class Logger extends BaseObject * @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'); } /** @@ -246,17 +192,11 @@ class Logger extends BaseObject * @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'); } /** @@ -267,54 +207,43 @@ class Logger extends BaseObject * @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); + } }