|
|
|
@ -62,24 +62,22 @@ use function strtr;
|
|
|
|
|
* MonoLog is an example implementing this interface.
|
|
|
|
|
*/
|
|
|
|
|
class Log implements ILogger, IDataLogger {
|
|
|
|
|
private IWriter $logger;
|
|
|
|
|
private ?SystemConfig $config;
|
|
|
|
|
private ?bool $logConditionSatisfied = null;
|
|
|
|
|
private ?Normalizer $normalizer;
|
|
|
|
|
private ?IRegistry $crashReporters;
|
|
|
|
|
private ?IEventDispatcher $eventDispatcher;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param IWriter $logger The logger that should be used
|
|
|
|
|
* @param SystemConfig $config the system config object
|
|
|
|
|
* @param SystemConfig|null $config the system config object
|
|
|
|
|
* @param Normalizer|null $normalizer
|
|
|
|
|
* @param IRegistry|null $registry
|
|
|
|
|
* @param IRegistry|null $crashReporters
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
IWriter $logger,
|
|
|
|
|
private IWriter $logger,
|
|
|
|
|
SystemConfig $config = null,
|
|
|
|
|
Normalizer $normalizer = null,
|
|
|
|
|
IRegistry $registry = null
|
|
|
|
|
private ?IRegistry $crashReporters = null
|
|
|
|
|
) {
|
|
|
|
|
// FIXME: Add this for backwards compatibility, should be fixed at some point probably
|
|
|
|
|
if ($config === null) {
|
|
|
|
@ -87,13 +85,11 @@ class Log implements ILogger, IDataLogger {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->config = $config;
|
|
|
|
|
$this->logger = $logger;
|
|
|
|
|
if ($normalizer === null) {
|
|
|
|
|
$this->normalizer = new Normalizer();
|
|
|
|
|
} else {
|
|
|
|
|
$this->normalizer = $normalizer;
|
|
|
|
|
}
|
|
|
|
|
$this->crashReporters = $registry;
|
|
|
|
|
$this->eventDispatcher = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -211,6 +207,9 @@ class Log implements ILogger, IDataLogger {
|
|
|
|
|
*/
|
|
|
|
|
public function log(int $level, string $message, array $context = []) {
|
|
|
|
|
$minLevel = $this->getLogLevel($context);
|
|
|
|
|
if ($level < $minLevel && (($this->crashReporters?->hasReporters() ?? false) === false)) {
|
|
|
|
|
return; // we already know that log will be fully ignored
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
array_walk($context, [$this->normalizer, 'format']);
|
|
|
|
|
|
|
|
|
@ -241,9 +240,7 @@ class Log implements ILogger, IDataLogger {
|
|
|
|
|
$this->crashReporters->delegateMessage($entry['message'], $messageContext);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if ($this->crashReporters !== null) {
|
|
|
|
|
$this->crashReporters->delegateBreadcrumb($entry['message'], 'log', $context);
|
|
|
|
|
}
|
|
|
|
|
$this->crashReporters?->delegateBreadcrumb($entry['message'], 'log', $context);
|
|
|
|
|
}
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
// make sure we dont hard crash if logging fails
|
|
|
|
@ -329,8 +326,8 @@ class Log implements ILogger, IDataLogger {
|
|
|
|
|
$level = $context['level'] ?? ILogger::ERROR;
|
|
|
|
|
|
|
|
|
|
$minLevel = $this->getLogLevel($context);
|
|
|
|
|
if ($level < $minLevel && ($this->crashReporters === null || !$this->crashReporters->hasReporters())) {
|
|
|
|
|
return;
|
|
|
|
|
if ($level < $minLevel && (($this->crashReporters?->hasReporters() ?? false) === false)) {
|
|
|
|
|
return; // we already know that log will be fully ignored
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if an error is raised before the autoloader is properly setup, we can't serialize exceptions
|
|
|
|
|