X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FLogger.php;h=6b8112796f557f00dea156a9c22fef3993097584;hb=f68b3c7c4ec9c7c98054035957db178d5071542c;hp=6102baa5a5cb2ab73f564596494deb83a36fa669;hpb=8f9c0fe14956efbcaf0db9dbfb83222e18e0ab2f;p=friendica.git diff --git a/src/Core/Logger.php b/src/Core/Logger.php index 6102baa5a5..6b8112796f 100644 --- a/src/Core/Logger.php +++ b/src/Core/Logger.php @@ -5,8 +5,8 @@ namespace Friendica\Core; use Friendica\BaseObject; +use Friendica\Factory\LoggerFactory; use Friendica\Network\HTTPException\InternalServerErrorException; -use Friendica\Util\LoggerFactory; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; @@ -16,35 +16,29 @@ use Psr\Log\LogLevel; class Logger extends BaseObject { /** - * @deprecated 2019.03 use Logger::error() instead * @see Logger::error() */ - const WARNING = 0; + const WARNING = LogLevel::ERROR; /** - * @deprecated 2019.03 use Logger::warning() instead * @see Logger::warning() */ - const INFO = 1; + const INFO = LogLevel::WARNING; /** - * @deprecated 2019.03 use Logger::notice() instead * @see Logger::notice() */ - const TRACE = 2; + const TRACE = LogLevel::NOTICE; /** - * @deprecated 2019.03 use Logger::info() instead * @see Logger::info() */ - const DEBUG = 3; + const DEBUG = LogLevel::INFO; /** - * @deprecated 2019.03 use Logger::debug() instead * @see Logger::debug() */ - const DATA = 4; + const DATA = LogLevel::DEBUG; /** - * @deprecated 2019.03 use Logger::debug() instead * @see Logger::debug() */ - const ALL = 5; + const ALL = LogLevel::DEBUG; /** * @var array the legacy loglevels @@ -83,14 +77,18 @@ class Logger extends BaseObject { $debugging = Config::get('system', 'debugging'); $logfile = Config::get('system', 'logfile'); - $loglevel = intval(Config::get('system', 'loglevel')); + $loglevel = Config::get('system', 'loglevel'); if (!$debugging || !$logfile) { return; } + $loglevel = self::mapLegacyConfigDebugLevel((string)$loglevel); + LoggerFactory::addStreamHandler($logger, $logfile, $loglevel); + self::$logger = $logger; + $logfile = Config::get('system', 'dlogfile'); if (!$logfile) { @@ -103,15 +101,51 @@ class Logger extends BaseObject LoggerFactory::addStreamHandler(self::$devLogger, $logfile, LogLevel::DEBUG); } + /** + * Mapping a legacy level to the PSR-3 compliant levels + * @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#5-psrlogloglevel + * + * @param string $level the level to be mapped + * + * @return string the PSR-3 compliant level + */ + private static function mapLegacyConfigDebugLevel($level) + { + switch ($level) { + // legacy WARNING + case "0": + return LogLevel::ERROR; + // legacy INFO + case "1": + return LogLevel::WARNING; + // legacy TRACE + case "2": + return LogLevel::NOTICE; + // legacy DEBUG + case "3": + return LogLevel::INFO; + // legacy DATA + case "4": + return LogLevel::DEBUG; + // legacy ALL + case "5": + return LogLevel::DEBUG; + // default if nothing set + default: + return $level; + } + } + /** * System is unusable. + * * @see LoggerInterface::emergency() * * @param string $message * @param array $context * * @return void - * + * @throws \Exception */ public static function emergency($message, $context = []) { @@ -135,7 +169,7 @@ class Logger extends BaseObject * @param array $context * * @return void - * + * @throws \Exception */ public static function alert($message, $context = []) { @@ -158,7 +192,7 @@ class Logger extends BaseObject * @param array $context * * @return void - * + * @throws \Exception */ public static function critical($message, $context = []) { @@ -180,11 +214,12 @@ 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; } @@ -204,7 +239,7 @@ class Logger extends BaseObject * @param array $context * * @return void - * + * @throws \Exception */ public static function warning($message, $context = []) { @@ -225,7 +260,7 @@ class Logger extends BaseObject * @param array $context * * @return void - * + * @throws \Exception */ public static function notice($message, $context = []) { @@ -248,7 +283,7 @@ class Logger extends BaseObject * @param array $context * * @return void - * + * @throws \Exception */ public static function info($message, $context = []) { @@ -269,6 +304,7 @@ class Logger extends BaseObject * @param array $context * * @return void + * @throws \Exception */ public static function debug($message, $context = []) { @@ -281,64 +317,36 @@ class Logger extends BaseObject self::getApp()->saveTimestamp($stamp1, 'file'); } - /** - * Mapping a legacy level to the PSR-3 compliant levels - * @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#5-psrlogloglevel - * - * @param int $level the level to be mapped - * - * @return string the PSR-3 compliant level - */ - private static function mapPSR3Level($level) - { - switch ($level) { - case self::WARNING: - return LogLevel::ERROR; - case self::INFO: - return LogLevel::WARNING; - case self::TRACE: - return LogLevel::NOTICE; - case self::DEBUG: - return LogLevel::INFO; - case self::DATA: - return LogLevel::DEBUG; - case self::ALL: - return LogLevel::DEBUG; - default: - return LogLevel::CRITICAL; - } - } - /** * @brief Logs the given message at the given log level * * @param string $msg - * @param int $level + * @param string $level * + * @throws \Exception * @deprecated since 2019.03 Use Logger::debug() Logger::info() , ... instead */ - public static function log($msg, $level = self::INFO) + public static function log($msg, $level = LogLevel::INFO) { if (!isset(self::$logger)) { return; } - $loglevel = self::mapPSR3Level($level); - $stamp1 = microtime(true); - self::$logger->log($loglevel, $msg); + 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 - */ + * @throws \Exception + */ public static function devLog($msg, $level = LogLevel::DEBUG) { if (!isset(self::$logger)) {