-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
205 additions
and
76 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
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,35 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Nettrine\DBAL\Logger; | ||
|
||
use Psr\Log\AbstractLogger; | ||
use Stringable; | ||
|
||
class SnapshotLogger extends AbstractLogger | ||
{ | ||
|
||
/** @var array<int, array{level: mixed, message: string, context: mixed[], timestamp: int}> */ | ||
protected array $snapshots = []; | ||
|
||
/** | ||
* @param mixed[] $context | ||
*/ | ||
public function log(mixed $level, Stringable|string $message, array $context = []): void | ||
{ | ||
$this->snapshots[] = [ | ||
'level' => $level, | ||
'message' => (string) $message, | ||
'context' => $context, | ||
'timestamp' => time(), | ||
]; | ||
} | ||
|
||
/** | ||
* @return array<int, array{duration:int}> | ||
*/ | ||
public function getQueries(): array | ||
{ | ||
return []; | ||
} | ||
|
||
} |
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,30 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Nettrine\DBAL\Middleware; | ||
|
||
use Doctrine\DBAL\Driver; | ||
use Doctrine\DBAL\Driver\Middleware; | ||
use Doctrine\DBAL\Logging\Driver as LoggingDriver; | ||
use Nettrine\DBAL\Logger\SnapshotLogger; | ||
|
||
class TracyMiddleware implements Middleware | ||
{ | ||
|
||
protected SnapshotLogger $logger; | ||
|
||
public function __construct() | ||
{ | ||
$this->logger = new SnapshotLogger(); | ||
} | ||
|
||
public function wrap(Driver $driver): Driver | ||
{ | ||
return new LoggingDriver($driver, $this->logger); | ||
} | ||
|
||
public function getLogger(): SnapshotLogger | ||
{ | ||
return $this->logger; | ||
} | ||
|
||
} |
Oops, something went wrong.