Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Add option to disable tracy exception render (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
bckp authored Sep 20, 2022
1 parent 6b4b5ba commit 30935a8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
5 changes: 3 additions & 2 deletions src/CustomChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Mallgroup\Monolog;

use Mallgroup\Monolog\Logger as CustomLogger;
use Monolog\DateTimeImmutable;
use Monolog\Handler\HandlerInterface;
use Monolog\Logger as MonologLogger;
use Nette\SmartObject;
Expand Down Expand Up @@ -57,9 +58,9 @@ public function getProcessors(): array
return $this->parentLogger->getProcessors();
}

public function addRecord(int $level, string $message, array $context = []): bool
public function addRecord(int $level, string $message, array $context = [], DateTimeImmutable $datetime = null): bool
{
return $this->parentLogger->addRecord($level, $message, array_merge(['channel' => $this->name], $context));
return $this->parentLogger->addRecord($level, $message, array_merge(['channel' => $this->name], $context), $datetime);
}

/**
Expand Down
47 changes: 26 additions & 21 deletions src/DI/MonologExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function getConfigSchema(): Schema
'tracyDefinition' => Expect::string('tracy.logger'),
'tracyHook' => Expect::bool(true),
'tracyBaseUrl' => Expect::string(),
'tracyRenderException' => Expect::bool(true),
'usePriorityProcessor' => Expect::bool(true),
'fallback' => Expect::structure([
'register' => Expect::bool(false),
Expand Down Expand Up @@ -290,37 +291,41 @@ private function hookTracy(): void
->addDefinition($this->prefix('tracy'))
->setFactory(MonologAdapter::class, [
'monolog' => $this->prefix('@logger'),
'blueScreenRenderer' => $this->prefix('@blueScreenRenderer'),
'blueScreenRenderer' => $this->config->tracyRenderException
? $this->prefix('@blueScreenRenderer')
: null,
'email' => Debugger::$email,
'accessPriority' => $this->config->accessPriority,
])
->setAutowired(false);

$builder
->addDefinition($this->prefix('blueScreenRenderer'))
->setFactory(BlueScreenRenderer::class, [
'directory' => $this->config->logDir,
])
->setAutowired(false);

$this->processors[] = new PriorityDefinition(
if ($this->config->tracyRenderException) {
$builder
->addDefinition($this->prefix('processor.tracyException'))
->setFactory(TracyExceptionProcessor::class, [
'blueScreenRenderer' => $this->prefix('@blueScreenRenderer'),
]),
100
);

if ($this->config->tracyBaseUrl) {
->addDefinition($this->prefix('blueScreenRenderer'))
->setFactory(BlueScreenRenderer::class, [
'directory' => $this->config->logDir,
])
->setAutowired(false);

$this->processors[] = new PriorityDefinition(
$builder
->addDefinition($this->prefix('processor.tracyBaseUrl'))
->setFactory(TracyUrlProcessor::class, [
'baseUrl' => $this->config->tracyBaseUrl,
->addDefinition($this->prefix('processor.tracyException'))
->setFactory(TracyExceptionProcessor::class, [
'blueScreenRenderer' => $this->prefix('@blueScreenRenderer'),
]),
10);
100
);

if ($this->config->tracyBaseUrl) {
$this->processors[] = new PriorityDefinition(
$builder
->addDefinition($this->prefix('processor.tracyBaseUrl'))
->setFactory(TracyUrlProcessor::class, [
'baseUrl' => $this->config->tracyBaseUrl,
'blueScreenRenderer' => $this->prefix('@blueScreenRenderer'),
]),
10);
}
}

if ($this->config->tracyHook === true) {
Expand Down
11 changes: 7 additions & 4 deletions src/Tracy/MonologAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,20 @@ class MonologAdapter extends Logger
self::CRITICAL => MonologLogger::CRITICAL,
];
private MonologLogger $monolog;
private BlueScreenRenderer $blueScreenRenderer;
private ?BlueScreenRenderer $blueScreenRenderer;
private string $accessPriority;

public function __construct(
MonologLogger $monolog,
BlueScreenRenderer $blueScreenRenderer,
?BlueScreenRenderer $blueScreenRenderer = NULL,
string $email = NULL,
string $accessPriority = self::INFO
)
{
parent::__construct($blueScreenRenderer->directory, $email);
parent::__construct(
$blueScreenRenderer->directory ?? null,
$email
);
$this->monolog = $monolog;
$this->blueScreenRenderer = $blueScreenRenderer;
$this->accessPriority = $accessPriority;
Expand Down Expand Up @@ -75,7 +78,7 @@ public function log($message, $level = self::INFO): ?string
$context['exception'] = $message;
}

$exceptionFile = $message instanceof \Throwable ? $this->getExceptionFile($message) : NULL;
$exceptionFile = $message instanceof \Throwable && $this->blueScreenRenderer ? $this->getExceptionFile($message) : NULL;

if ($this->email !== NULL && $this->mailer !== NULL && in_array($level, [self::ERROR, self::EXCEPTION, self::CRITICAL], TRUE)) {
$this->sendEmail(implode(' ', [
Expand Down

0 comments on commit 30935a8

Please sign in to comment.