mirror of
https://github.com/friendica/friendica
synced 2025-04-30 21:44:22 +02:00
Refactoring Logging to use Configuration
This commit is contained in:
parent
eafcf3592d
commit
80f1feabe5
13 changed files with 141 additions and 146 deletions
|
@ -8,10 +8,6 @@
|
|||
*/
|
||||
namespace Friendica\Core;
|
||||
|
||||
use Friendica\Core\Config\ConfigCache;
|
||||
use Friendica\Core\Config\IConfigAdapter;
|
||||
use Friendica\Core\Config\IConfigCache;
|
||||
|
||||
/**
|
||||
* @brief Arbitrary system configuration storage
|
||||
*
|
||||
|
|
|
@ -55,6 +55,8 @@ class ConfigCache implements IConfigCache, IPConfigCache
|
|||
{
|
||||
if (isset($this->config[$cat][$key])) {
|
||||
return $this->config[$cat][$key];
|
||||
} elseif ($key == null && isset($this->config[$cat])) {
|
||||
return $this->config[$cat];
|
||||
} else {
|
||||
return '!<unset>!';
|
||||
}
|
||||
|
@ -65,8 +67,8 @@ class ConfigCache implements IConfigCache, IPConfigCache
|
|||
*/
|
||||
public function has($cat, $key = null)
|
||||
{
|
||||
return isset($this->config[$cat][$key])
|
||||
&& $this->config[$cat][$key] !== '!<unset>!';
|
||||
return (isset($this->config[$cat][$key]) && $this->config[$cat][$key] !== '!<unset>!') ||
|
||||
($key == null && isset($this->config[$cat]) && $this->config[$cat] !== '!<unset>!' && is_array($this->config[$cat]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,8 +107,8 @@ class ConfigCache implements IConfigCache, IPConfigCache
|
|||
*/
|
||||
public function hasP($uid, $cat, $key = null)
|
||||
{
|
||||
return isset($this->config[$uid][$cat][$key])
|
||||
&& $this->config[$uid][$cat][$key] !== '!<unset>!';
|
||||
return (isset($this->config[$uid][$cat][$key]) && $this->config[$uid][$cat][$key] !== '!<unset>!') ||
|
||||
($key == null && isset($this->config[$uid][$cat]) && $this->config[$uid][$cat] !== '!<unset>!' && is_array($this->config[$uid][$cat]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,6 +146,8 @@ class ConfigCache implements IConfigCache, IPConfigCache
|
|||
{
|
||||
if (isset($this->config[$uid][$cat][$key])) {
|
||||
return $this->config[$uid][$cat][$key];
|
||||
} elseif ($key == null && isset($this->config[$uid][$cat])) {
|
||||
return $this->config[$uid][$cat];
|
||||
} else {
|
||||
return '!<unset>!';
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
namespace Friendica\Core;
|
||||
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Factory\LoggerFactory;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
|
||||
|
@ -67,73 +65,22 @@ 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)
|
||||
{
|
||||
$debugging = Config::get('system', 'debugging');
|
||||
$logfile = Config::get('system', 'logfile');
|
||||
$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) {
|
||||
return;
|
||||
}
|
||||
|
||||
$developIp = Config::get('system', 'dlogip');
|
||||
|
||||
self::$devLogger = LoggerFactory::createDev('develop', $developIp);
|
||||
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
|
||||
* Sets the default dev-logging handler for Friendica.
|
||||
*
|
||||
* @param string $level the level to be mapped
|
||||
*
|
||||
* @return string the PSR-3 compliant level
|
||||
* @param LoggerInterface $logger The Logger instance of this Application
|
||||
*/
|
||||
private static function mapLegacyConfigDebugLevel($level)
|
||||
public static function setDevLogger($logger)
|
||||
{
|
||||
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;
|
||||
}
|
||||
self::$devLogger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue