1 | <?php |
||
15 | final class PsrSqlLoggerConfigurableLogLevels implements SQLLogger |
||
16 | { |
||
17 | /** @var LoggerInterface */ |
||
18 | private $logger; |
||
19 | |||
20 | /** @var float */ |
||
21 | private $start; |
||
22 | |||
23 | /** @var callable */ |
||
24 | private $startQueryCallable; |
||
25 | |||
26 | /** @var string */ |
||
27 | private $queryId; |
||
28 | |||
29 | /** @var string */ |
||
30 | private $defaultLogLevel; |
||
31 | |||
32 | /** @var LogLevelConfiguration|null */ |
||
33 | private $logLevelConfiguration; |
||
34 | |||
35 | public function __construct( |
||
36 | LoggerInterface $logger, |
||
37 | LogLevelConfiguration $logLevelMapping, |
||
38 | string $defaultLogLevel = LogLevel::INFO |
||
39 | ) { |
||
40 | $this->logger = $logger; |
||
41 | $this->logLevelConfiguration = $logLevelMapping; |
||
42 | $this->defaultLogLevel = $defaultLogLevel; |
||
43 | $this->startQueryCallable = $this->getStartQueryCallable($defaultLogLevel); |
||
44 | } |
||
45 | |||
46 | private function getStartQueryCallable(string $level): callable |
||
60 | |||
61 | private function getLoggerCallable(string $level) : array |
||
65 | |||
66 | public function startQuery($sql, array $params = null, array $types = null) : void |
||
67 | { |
||
68 | $this->queryId = uniqid('', true); |
||
69 | |||
70 | $this->start = microtime(true); |
||
71 | |||
72 | call_user_func($this->startQueryCallable, 'Query started', array_merge( |
||
73 | $this->getStartQueryContext($sql, $params, $types), |
||
74 | [ |
||
75 | 'query_id' => $this->queryId, |
||
76 | ] |
||
77 | )); |
||
78 | } |
||
79 | |||
80 | protected function getStartQueryContext($sql, array $params = null, array $types = null) : array |
||
87 | |||
88 | public function stopQuery() : void |
||
100 | |||
101 | private function getStopQueryCallable(float $durationInSeconds): callable |
||
105 | |||
106 | private function getApplicableLogLevel(float $durationInSeconds): ?string |
||
107 | { |
||
112 | } |
||
113 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.