-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tracy to PSR bridge: calls original Tracy logger directly instead of …
…via Monolog to prevent modifying logs prevents changing log level to PSR-compatible and prevents modifying message by Monolog
- Loading branch information
Showing
7 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace OriNette\Monolog\Tracy; | ||
|
||
use Tracy\Bridges\Psr\TracyToPsrLoggerAdapter; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ToggleableTracyToPsrLoggerAdapter extends TracyToPsrLoggerAdapter | ||
{ | ||
|
||
public bool $enabled = true; | ||
|
||
/** | ||
* @param array<mixed> $context | ||
*/ | ||
public function log($level, $message, array $context = []): void | ||
{ | ||
if (!$this->enabled) { | ||
return; | ||
} | ||
|
||
parent::log($level, $message, $context); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
tests/Unit/Tracy/ToggleableTracyToPsrLoggerAdapterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\OriNette\Monolog\Unit\Tracy; | ||
|
||
use OriNette\Monolog\Tracy\ToggleableTracyToPsrLoggerAdapter; | ||
use PHPUnit\Framework\TestCase; | ||
use Tests\OriNette\Monolog\Doubles\TracyTestLogger; | ||
|
||
final class ToggleableTracyToPsrLoggerAdapterTest extends TestCase | ||
{ | ||
|
||
public function test(): void | ||
{ | ||
$logger = new TracyTestLogger(); | ||
$adapter = new ToggleableTracyToPsrLoggerAdapter($logger); | ||
|
||
self::assertCount(0, $logger->getRecords()); | ||
|
||
$adapter->error('test'); | ||
self::assertCount(1, $logger->getRecords()); | ||
|
||
$adapter->enabled = false; | ||
$adapter->error('test'); | ||
self::assertCount(1, $logger->getRecords()); | ||
|
||
$adapter->enabled = true; | ||
$adapter->error('test'); | ||
self::assertCount(2, $logger->getRecords()); | ||
} | ||
|
||
} |