*/
class LoggerFactory
{
+ /**
+ * A list of classes, which shouldn't get logged
+ * @var array
+ */
+ private static $ignoreClassList = [
+ Logger::class,
+ Profiler::class,
+ WorkerLogger::class
+ ];
+
/**
* Creates a new PSR-3 compliant logger instances
*
$logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor());
$logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor());
$logger->pushProcessor(new Monolog\Processor\UidProcessor());
- $logger->pushProcessor(new FriendicaIntrospectionProcessor(LogLevel::DEBUG, [Logger::class, Profiler::class, WorkerLogger::class]));
+ $logger->pushProcessor(new FriendicaIntrospectionProcessor(LogLevel::DEBUG, self::$ignoreClassList));
$debugging = $config->get('system', 'debugging');
$stream = $config->get('system', 'logfile');
$logger->pushProcessor(new Monolog\Processor\PsrLogMessageProcessor());
$logger->pushProcessor(new Monolog\Processor\ProcessIdProcessor());
$logger->pushProcessor(new Monolog\Processor\UidProcessor());
- $logger->pushProcessor(new FriendicaIntrospectionProcessor(LogLevel::DEBUG, ['Friendica\\Core\\Logger']));
+ $logger->pushProcessor(new FriendicaIntrospectionProcessor(LogLevel::DEBUG, self::$ignoreClassList));
$logger->pushHandler(new FriendicaDevelopHandler($developerIp));
if (!is_int($loglevel)) {
$loglevel = LogLevel::NOTICE;
}
+
+ // if the stream is a file and it isn't writeable, add a null handler and return
+ if (is_file($stream) && !is_writable($stream)) {
+ $logger->pushHandler(new Monolog\Handler\NullHandler());
+ return;
+ }
+
$fileHandler = new Monolog\Handler\StreamHandler($stream, $loglevel);
$formatter = new Monolog\Formatter\LineFormatter("%datetime% %channel% [%level_name%]: %message% %context% %extra%\n");
public static function create(IConfigCache $configCache)
{
$enabled = $configCache->get('system', 'profiler');
- $enabled = isset($enabled) && $enabled !== '!<unset>!';
+ $enabled = isset($enabled) && $enabled !== '0';
$renderTime = $configCache->get('rendertime', 'callstack');
- $renderTime = isset($renderTime) && $renderTime !== '!<unset>!';
+ $renderTime = isset($renderTime) && $renderTime !== '0';
return new Profiler($enabled, $renderTime);
}
namespace Friendica\Test\Util;
+use Friendica\Database\DBA;
use Mockery\MockInterface;
class DBAStub
private function checkMock()
{
if (!isset($this->dbaMock)) {
- $this->dbaMock = \Mockery::namedMock('Friendica\Database\DBA', 'Friendica\Test\Util\DBAStub');
+ $this->dbaMock = \Mockery::namedMock(DBA::class, DBAStub::class);
}
}
public function mockUpdate($args = [], $return = true, $times = null)
{
if (!isset($this->dbStructure)) {
- $this->dbStructure = \Mockery::mock('alias:Friendica\Database\DBStructure');
+ $this->dbStructure = \Mockery::mock('alias:' . DBStructure::class);
}
$this->dbStructure
public function mockExistsTable($tableName, $return = true, $times = null)
{
if (!isset($this->dbStructure)) {
- $this->dbStructure = \Mockery::mock('alias:Friendica\Database\DBStructure');
+ $this->dbStructure = \Mockery::mock('alias:' . DBStructure::class);
}
$this->dbStructure
namespace Friendica\Test\Util;
+use Friendica\Util\DateTimeFormat;
use Mockery\MockInterface;
trait DateTimeFormatMockTrait
public function mockUtcNow($time, $times = null)
{
if (!isset($this->dtfMock)) {
- $this->dtfMock = \Mockery::mock('alias:Friendica\Util\DateTimeFormat');
+ $this->dtfMock = \Mockery::mock('alias:'. DateTimeFormat::class);
}
$this->dtfMock
public function mockUtc($input, $time, $times = null)
{
if (!isset($this->dtfMock)) {
- $this->dtfMock = \Mockery::mock('alias:Friendica\Util\DateTimeFormat');
+ $this->dtfMock = \Mockery::mock('alias:' . DateTimeFormat::class);
}
$this->dtfMock
namespace Friendica\Test\Util;
+use Friendica\Core\L10n;
use Mockery\MockInterface;
trait L10nMockTrait
public function mockL10nT($input = null, $times = null, $return = null)
{
if (!isset($this->l10nMock)) {
- $this->l10nMock = \Mockery::mock('alias:Friendica\Core\L10n');
+ $this->l10nMock = \Mockery::mock('alias:' . L10n::class);
}
$with = isset($input) ? $input : \Mockery::any();
namespace Friendica\Test\Util;
+use Friendica\Core\Renderer;
use Mockery\MockInterface;
trait RendererMockTrait
public function mockGetMarkupTemplate($templateName, $return = '', $times = null)
{
if (!isset($this->rendererMock)) {
- $this->rendererMock = \Mockery::mock('alias:Friendica\Core\Renderer');
+ $this->rendererMock = \Mockery::mock('alias:' . Renderer::class);
}
$this->rendererMock
public function mockReplaceMacros($template, $args = [], $return = '', $times = null)
{
if (!isset($this->rendererMock)) {
- $this->rendererMock = \Mockery::mock('alias:Friendica\Core\Renderer');
+ $this->rendererMock = \Mockery::mock('alias:' . Renderer::class);
}
$this->rendererMock
namespace Friendica\Test\src\Core\Console;
+use Friendica\App\Mode;
use Friendica\Core\Console\Config;
/**
parent::setUp();
\Mockery::getConfiguration()->setConstantsMap([
- 'Friendica\App\Mode' => [
+ Mode::class => [
'DBCONFIGAVAILABLE' => 0
]
]);
- $mode = \Mockery::mock('Friendica\App\Mode');
+ $mode = \Mockery::mock(Mode::class);
$mode
->shouldReceive('has')
->andReturn(true);
// this is in the same namespace as Install for mocking 'function_exists'
namespace Friendica\Core;
+use Friendica\Network\CurlResult;
+use Friendica\Object\Image;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\L10nMockTrait;
use Friendica\Test\Util\VFSTrait;
+use Friendica\Util\Network;
/**
* @runTestsInSeparateProcesses
$this->mockL10nT();
// Mocking the CURL Response
- $curlResult = \Mockery::mock('Friendica\Network\CurlResult');
+ $curlResult = \Mockery::mock(CurlResult::class);
$curlResult
->shouldReceive('getReturnCode')
->andReturn('404');
->andReturn('test Error');
// Mocking the CURL Request
- $networkMock = \Mockery::mock('alias:Friendica\Util\Network');
+ $networkMock = \Mockery::mock('alias:' . Network::class);
$networkMock
->shouldReceive('fetchUrlFull')
->with('https://test/install/testrewrite')
$this->mockL10nT();
// Mocking the failed CURL Response
- $curlResultF = \Mockery::mock('Friendica\Network\CurlResult');
+ $curlResultF = \Mockery::mock(CurlResult::class);
$curlResultF
->shouldReceive('getReturnCode')
->andReturn('404');
// Mocking the working CURL Response
- $curlResultW = \Mockery::mock('Friendica\Network\CurlResult');
+ $curlResultW = \Mockery::mock(CurlResult::class);
$curlResultW
->shouldReceive('getReturnCode')
->andReturn('204');
// Mocking the CURL Request
- $networkMock = \Mockery::mock('alias:Friendica\Util\Network');
+ $networkMock = \Mockery::mock('alias:' . Network::class);
$networkMock
->shouldReceive('fetchUrlFull')
->with('https://test/install/testrewrite')
{
$this->mockL10nT();
- $imageMock = \Mockery::mock('alias:Friendica\Object\Image');
+ $imageMock = \Mockery::mock('alias:'. Image::class);
$imageMock
->shouldReceive('supportedTypes')
->andReturn(['image/gif' => 'gif']);
{
$this->mockL10nT();
- $imageMock = \Mockery::mock('alias:Friendica\Object\Image');
+ $imageMock = \Mockery::mock('alias:' . Image::class);
$imageMock
->shouldReceive('supportedTypes')
->andReturn([]);
use Friendica\Test\MockedTest;
use Friendica\Util\Logger\WorkerLogger;
+use Psr\Log\LoggerInterface;
class WorkerLoggerTest extends MockedTest
{
*/
public function testGetWorkerIdZero()
{
- $logger = \Mockery::mock('Psr\Log\LoggerInterface');
+ $logger = \Mockery::mock(LoggerInterface::class);
$logger
->shouldReceive('alert')
->with('id length must be greater than 0.')
*/
public function testGetWorkerId()
{
- $logger = \Mockery::mock('Psr\Log\LoggerInterface');
+ $logger = \Mockery::mock(LoggerInterface::class);
for ($i = 1; $i < 14; $i++) {
$workLogger = new WorkerLogger($logger, 'test', $i);
$uid = $workLogger->getWorkerId();
*/
public function testEmergency($func, $msg, $context = [])
{
- $logger = \Mockery::mock('Psr\Log\LoggerInterface');
+ $logger = \Mockery::mock(LoggerInterface::class);
$workLogger = new WorkerLogger($logger, 'test');
$testContext = $context;
$testContext['worker_id'] = $workLogger->getWorkerId();
*/
public function testLog()
{
- $logger = \Mockery::mock('Psr\Log\LoggerInterface');
+ $logger = \Mockery::mock(LoggerInterface::class);
$workLogger = new WorkerLogger($logger, 'test');
$context = $testContext = ['test' => 'it'];
$testContext['worker_id'] = $workLogger->getWorkerId();
{
parent::setUp();
- $this->logger = \Mockery::mock('Psr\Log\LoggerInterface');
+ $this->logger = \Mockery::mock(LoggerInterface::class);
}
/**