-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
PsrLogger.php
46 lines (35 loc) · 943 Bytes
/
PsrLogger.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php declare(strict_types = 1);
namespace Nettrine\DBAL\Logger;
use Doctrine\DBAL\Logging\SQLLogger;
use Psr\Log\LoggerInterface;
class PsrLogger implements SQLLogger
{
/** @var LoggerInterface */
private $logger;
/** @var float */
private $startTime;
/** @var string */
private $query;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
/**
* @param string $sql
* @param mixed[]|null $params
* @param mixed[]|null $types
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
*/
public function startQuery($sql, ?array $params = null, ?array $types = null): void
{
$this->query = $sql;
$this->startTime = microtime(true);
}
public function stopQuery(): void
{
$time = round((microtime(true) - $this->startTime) * 1000);
$this->logger->debug('Query: ' . $this->query, [
'time' => sprintf('%s ms', $time),
]);
}
}