2018-12-30 20:42:56 +00:00
|
|
|
<?php
|
2020-02-09 14:45:36 +00:00
|
|
|
/**
|
2023-01-01 14:36:24 +00:00
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
2020-02-09 14:45:36 +00:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-12-30 20:42:56 +00:00
|
|
|
|
2021-10-23 10:22:27 +00:00
|
|
|
namespace Friendica\Core\Logger\Factory;
|
2018-12-30 20:42:56 +00:00
|
|
|
|
2021-10-26 19:44:29 +00:00
|
|
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
2023-07-23 01:21:41 +00:00
|
|
|
use Friendica\Core\Hooks\Capability\ICanCreateInstances;
|
|
|
|
use Friendica\Core\Logger\Capability\LogChannel;
|
2023-07-16 22:10:15 +00:00
|
|
|
use Friendica\Core\Logger\Type\ProfilerLogger as ProfilerLoggerClass;
|
|
|
|
use Friendica\Util\Profiler;
|
2018-12-30 20:42:56 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2021-10-23 10:26:06 +00:00
|
|
|
use Psr\Log\NullLogger;
|
2023-07-02 21:56:56 +00:00
|
|
|
use Throwable;
|
2018-12-30 20:42:56 +00:00
|
|
|
|
|
|
|
/**
|
2023-07-02 21:56:56 +00:00
|
|
|
* The logger factory for the core logging instances
|
2018-12-30 20:42:56 +00:00
|
|
|
*/
|
2021-10-23 10:22:27 +00:00
|
|
|
class Logger
|
2018-12-30 20:42:56 +00:00
|
|
|
{
|
2023-07-02 21:56:56 +00:00
|
|
|
/** @var string The channel */
|
2023-01-15 21:31:19 +00:00
|
|
|
protected $channel;
|
2019-09-17 14:47:00 +00:00
|
|
|
|
2023-07-02 21:56:56 +00:00
|
|
|
public function __construct(string $channel = LogChannel::DEFAULT)
|
2019-07-21 18:24:16 +00:00
|
|
|
{
|
2023-07-02 21:56:56 +00:00
|
|
|
$this->channel = $channel;
|
2019-07-21 18:24:16 +00:00
|
|
|
}
|
|
|
|
|
2023-07-21 20:41:36 +00:00
|
|
|
public function create(ICanCreateInstances $instanceCreator, IManageConfigValues $config, Profiler $profiler): LoggerInterface
|
2018-12-30 20:42:56 +00:00
|
|
|
{
|
2023-07-02 21:56:56 +00:00
|
|
|
if (empty($config->get('system', 'debugging') ?? false)) {
|
2023-01-15 21:31:19 +00:00
|
|
|
return new NullLogger();
|
2019-03-03 19:32:27 +00:00
|
|
|
}
|
|
|
|
|
2023-07-02 21:56:56 +00:00
|
|
|
$name = $config->get('system', 'logger_config') ?? '';
|
2019-03-03 19:32:27 +00:00
|
|
|
|
2023-01-15 21:31:19 +00:00
|
|
|
try {
|
2023-07-16 22:10:15 +00:00
|
|
|
/** @var LoggerInterface $logger */
|
2023-07-21 20:41:36 +00:00
|
|
|
$logger = $instanceCreator->create(LoggerInterface::class, $name, [$this->channel]);
|
2023-07-16 22:10:15 +00:00
|
|
|
if ($config->get('system', 'profiling') ?? false) {
|
|
|
|
return new ProfilerLoggerClass($logger, $profiler);
|
|
|
|
} else {
|
|
|
|
return $logger;
|
|
|
|
}
|
2023-07-02 21:56:56 +00:00
|
|
|
} catch (Throwable $e) {
|
2023-01-15 21:31:19 +00:00
|
|
|
// No logger ...
|
|
|
|
return new NullLogger();
|
2019-02-03 21:22:04 +00:00
|
|
|
}
|
2018-12-30 20:42:56 +00:00
|
|
|
}
|
|
|
|
}
|