Bugfixing
This commit is contained in:
parent
83f187a047
commit
6150c2fa9c
|
@ -8,6 +8,7 @@ use Detection\MobileDetect;
|
||||||
use DOMDocument;
|
use DOMDocument;
|
||||||
use DOMXPath;
|
use DOMXPath;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Friendica\Core\Logger;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
|
@ -89,7 +89,10 @@ class Logger extends BaseObject
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoggerFactory::addStreamHandler($logger, $logfile, $loglevel);
|
$level = self::mapPSR3Level($loglevel);
|
||||||
|
LoggerFactory::addStreamHandler($logger, $logfile, $level);
|
||||||
|
|
||||||
|
self::$logger = $logger;
|
||||||
|
|
||||||
$logfile = Config::get('system', 'dlogfile');
|
$logfile = Config::get('system', 'dlogfile');
|
||||||
|
|
||||||
|
@ -185,6 +188,7 @@ class Logger extends BaseObject
|
||||||
public static function error($message, $context = [])
|
public static function error($message, $context = [])
|
||||||
{
|
{
|
||||||
if (!isset(self::$logger)) {
|
if (!isset(self::$logger)) {
|
||||||
|
echo "not set!?\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ class LoggerFactory
|
||||||
public static function addStreamHandler($logger, $stream, $level = LogLevel::NOTICE)
|
public static function addStreamHandler($logger, $stream, $level = LogLevel::NOTICE)
|
||||||
{
|
{
|
||||||
if ($logger instanceof Monolog\Logger) {
|
if ($logger instanceof Monolog\Logger) {
|
||||||
$fileHandler = new Monolog\Handler\StreamHandler($stream . ".1", Monolog\Logger::toMonologLevel($level));
|
$fileHandler = new Monolog\Handler\StreamHandler($stream, Monolog\Logger::toMonologLevel($level));
|
||||||
|
|
||||||
$formatter = new Monolog\Formatter\LineFormatter("%datetime% %channel% [%level_name%]: %message% %context% %extra%\n");
|
$formatter = new Monolog\Formatter\LineFormatter("%datetime% %channel% [%level_name%]: %message% %context% %extra%\n");
|
||||||
$fileHandler->setFormatter($formatter);
|
$fileHandler->setFormatter($formatter);
|
||||||
|
@ -78,4 +78,32 @@ class LoggerFactory
|
||||||
throw new InternalServerErrorException('Logger instance incompatible for MonologFactory');
|
throw new InternalServerErrorException('Logger instance incompatible for MonologFactory');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method enables the test mode of a given logger
|
||||||
|
*
|
||||||
|
* @param LoggerInterface $logger The logger
|
||||||
|
*
|
||||||
|
* @return Monolog\Handler\TestHandler the Handling for tests
|
||||||
|
*
|
||||||
|
* @throws InternalServerErrorException if the logger is incompatible to the logger factory
|
||||||
|
*/
|
||||||
|
public static function enableTest($logger)
|
||||||
|
{
|
||||||
|
if ($logger instanceof Monolog\Logger) {
|
||||||
|
// disable every handler so far
|
||||||
|
$logger->pushHandler(new Monolog\Handler\NullHandler());
|
||||||
|
|
||||||
|
// enable the test handler
|
||||||
|
$fileHandler = new Monolog\Handler\TestHandler();
|
||||||
|
$formatter = new Monolog\Formatter\LineFormatter("%datetime% %channel% [%level_name%]: %message% %context% %extra%\n");
|
||||||
|
$fileHandler->setFormatter($formatter);
|
||||||
|
|
||||||
|
$logger->pushHandler($fileHandler);
|
||||||
|
|
||||||
|
return $fileHandler;
|
||||||
|
} else {
|
||||||
|
throw new InternalServerErrorException('Logger instance incompatible for MonologFactory');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ use Friendica\Core\PConfig;
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
|
use Friendica\Util\LoggerFactory;
|
||||||
|
use Monolog\Handler\TestHandler;
|
||||||
|
|
||||||
require_once __DIR__ . '/../../include/api.php';
|
require_once __DIR__ . '/../../include/api.php';
|
||||||
|
|
||||||
|
@ -22,6 +24,11 @@ require_once __DIR__ . '/../../include/api.php';
|
||||||
*/
|
*/
|
||||||
class ApiTest extends DatabaseTest
|
class ApiTest extends DatabaseTest
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var TestHandler Can handle log-outputs
|
||||||
|
*/
|
||||||
|
protected $logOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create variables used by tests.
|
* Create variables used by tests.
|
||||||
*/
|
*/
|
||||||
|
@ -30,6 +37,7 @@ class ApiTest extends DatabaseTest
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->app = BaseObject::getApp();
|
$this->app = BaseObject::getApp();
|
||||||
|
$this->logOutput = LoggerFactory::enableTest($this->app->getLogger());
|
||||||
|
|
||||||
// User data that the test database is populated with
|
// User data that the test database is populated with
|
||||||
$this->selfUser = [
|
$this->selfUser = [
|
||||||
|
|
|
@ -41,6 +41,7 @@ class BaseObjectTest extends TestCase
|
||||||
{
|
{
|
||||||
$logger = $logger = LoggerFactory::create('test');
|
$logger = $logger = LoggerFactory::create('test');
|
||||||
$app = new App(__DIR__ . '/../../', $logger);
|
$app = new App(__DIR__ . '/../../', $logger);
|
||||||
|
LoggerFactory::enableTest($logger);
|
||||||
$this->assertNull($this->baseObject->setApp($app));
|
$this->assertNull($this->baseObject->setApp($app));
|
||||||
$this->assertEquals($app, $this->baseObject->getApp());
|
$this->assertEquals($app, $this->baseObject->getApp());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user