1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Doctrine MongoDBBundle |
5
|
|
|
* |
6
|
|
|
* The code was originally distributed inside the Symfony framework. |
7
|
|
|
* |
8
|
|
|
* (c) Fabien Potencier <[email protected]> |
9
|
|
|
* (c) Doctrine Project |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Saxulum\SaxulumWebProfiler\Logger; |
16
|
|
|
|
17
|
|
|
use Psr\Log\LoggerInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* A lightweight query logger. |
21
|
|
|
* |
22
|
|
|
* @author Kris Wallsmith <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class DoctrineMongoDbLogger implements DoctrineMongoDbLoggerInterface |
25
|
|
|
{ |
26
|
|
|
private $logger; |
27
|
|
|
private $prefix; |
28
|
|
|
private $batchInsertTreshold; |
29
|
|
|
|
30
|
|
|
public function __construct(LoggerInterface $logger = null, $prefix = 'MongoDB query: ') |
31
|
|
|
{ |
32
|
|
|
$this->logger = $logger; |
33
|
|
|
$this->prefix = $prefix; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function setBatchInsertThreshold($batchInsertTreshold) |
37
|
|
|
{ |
38
|
|
|
$this->batchInsertTreshold = $batchInsertTreshold; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function logQuery(array $query) |
42
|
|
|
{ |
43
|
|
|
if (null === $this->logger) { |
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if (isset($query['batchInsert']) && null !== $this->batchInsertTreshold && $this->batchInsertTreshold <= $query['num']) { |
48
|
|
|
$query['data'] = '**'.$query['num'].' item(s)**'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
array_walk_recursive($query, function(&$value, $key) { |
|
|
|
|
52
|
|
|
if ($value instanceof \MongoBinData) { |
53
|
|
|
$value = base64_encode($value->bin); |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
if (is_float($value) && is_infinite($value)) { |
57
|
|
|
$value = ($value < 0 ? '-' : '') . 'Infinity'; |
58
|
|
|
return; |
59
|
|
|
} |
60
|
|
|
if (is_float($value) && is_nan($value)) { |
61
|
|
|
$value = 'NaN'; |
62
|
|
|
return; |
63
|
|
|
} |
64
|
|
|
}); |
65
|
|
|
|
66
|
|
|
$this->logger->debug($this->prefix.json_encode($query)); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.