1 | <?php |
||
8 | class Logger implements IListener |
||
9 | { |
||
10 | /** |
||
11 | * @var LoggerInterface $logger |
||
12 | */ |
||
13 | protected $logger; |
||
14 | |||
15 | /** |
||
16 | * @var bool логировать все запросы |
||
17 | */ |
||
18 | protected $logAllQueries=true; |
||
19 | |||
20 | /** |
||
21 | * @var bool логировать запросы с ошибками |
||
22 | */ |
||
23 | protected $logErrorQueries=true; |
||
24 | |||
25 | /** |
||
26 | * @var bool логировать медленные запросы |
||
27 | */ |
||
28 | protected $logSlowQueries=true; |
||
29 | |||
30 | /** |
||
31 | * @var int лимит времени выполнения запроса после которого он считается медленным (мс) |
||
32 | */ |
||
33 | protected $slowQueryLimitMs = 1000; |
||
34 | |||
35 | /** |
||
36 | * Logger constructor. |
||
37 | * @param LoggerInterface $logger |
||
38 | * @param bool $logAllQueries |
||
39 | * @param bool $logErrorQueries |
||
40 | * @param bool $logSlowQueries |
||
41 | * @param int $slowQueryLimitMs |
||
42 | */ |
||
43 | public function __construct( |
||
56 | |||
57 | /** |
||
58 | * @param LoggerInterface $logger |
||
59 | */ |
||
60 | public function setLogger(LoggerInterface $logger) |
||
65 | |||
66 | /** |
||
67 | * @param bool $logAllQueries |
||
68 | */ |
||
69 | public function setLogAllQueries($logAllQueries) |
||
74 | |||
75 | /** |
||
76 | * @param bool $logErrorQueries |
||
77 | */ |
||
78 | public function setLogErrorQueries($logErrorQueries) |
||
83 | |||
84 | /** |
||
85 | * @param bool $logSlowQueries |
||
86 | */ |
||
87 | public function setLogSlowQueries($logSlowQueries) |
||
92 | |||
93 | /** |
||
94 | * @param int $slowQueryLimitMs |
||
95 | */ |
||
96 | public function setSlowQueryLimitMs($slowQueryLimitMs) |
||
101 | |||
102 | |||
103 | public function onSuccess(array $query, array $response, $time) |
||
125 | |||
126 | public function onError(array $query, \Exception $e) |
||
138 | |||
139 | protected function getIndexName(array $query) |
||
145 | |||
146 | protected function getTimeRange($time) |
||
156 | } |