@@ -34,7 +34,7 @@ class SqlLogPanel extends DebugPanel
34
34
*
35
35
* @var array
36
36
*/
37
- protected array $ _loggers = [];
37
+ protected static array $ _loggers = [];
38
38
39
39
/**
40
40
* Initialize hook - configures logger.
@@ -47,34 +47,47 @@ class SqlLogPanel extends DebugPanel
47
47
public function initialize (): void
48
48
{
49
49
$ configs = ConnectionManager::configured ();
50
- $ includeSchemaReflection = (bool )Configure::read ('DebugKit.includeSchemaReflection ' );
51
50
52
51
foreach ($ configs as $ name ) {
53
- $ connection = ConnectionManager::get ($ name );
54
- if ($ connection ->configName () === 'debug_kit ' ) {
55
- continue ;
56
- }
57
- $ driver = $ connection ->getDriver ();
58
- $ logger = null ;
59
- if ($ driver instanceof Driver) {
60
- $ logger = $ driver ->getLogger ();
61
- } elseif (method_exists ($ connection , 'getLogger ' )) {
62
- // ElasticSearch connection holds the logger, not the Elastica Driver
63
- $ logger = $ connection ->getLogger ();
64
- }
52
+ static ::addConnection ($ name );
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Add a connection to the list of loggers.
58
+ *
59
+ * @param string $name The name of the connection to add.
60
+ * @return void
61
+ */
62
+ public static function addConnection (string $ name ): void
63
+ {
64
+ $ includeSchemaReflection = (bool )Configure::read ('DebugKit.includeSchemaReflection ' );
65
65
66
- if ($ logger instanceof DebugLog) {
67
- $ logger ->setIncludeSchema ($ includeSchemaReflection );
68
- $ this ->_loggers [] = $ logger ;
69
- continue ;
70
- }
71
- $ logger = new DebugLog ($ logger , $ name , $ includeSchemaReflection );
66
+ $ connection = ConnectionManager::get ($ name );
67
+ if ($ connection ->configName () === 'debug_kit ' ) {
68
+ return ;
69
+ }
70
+ $ driver = $ connection ->getDriver ();
71
+ $ logger = null ;
72
+ if ($ driver instanceof Driver) {
73
+ $ logger = $ driver ->getLogger ();
74
+ } elseif (method_exists ($ connection , 'getLogger ' )) {
75
+ // ElasticSearch connection holds the logger, not the Elastica Driver
76
+ $ logger = $ connection ->getLogger ();
77
+ }
72
78
73
- /** @var \Cake\Database\Driver $driver */
74
- $ driver ->setLogger ($ logger );
79
+ if ($ logger instanceof DebugLog) {
80
+ $ logger ->setIncludeSchema ($ includeSchemaReflection );
81
+ static ::$ _loggers [] = $ logger ;
75
82
76
- $ this -> _loggers [] = $ logger ;
83
+ return ;
77
84
}
85
+ $ logger = new DebugLog ($ logger , $ name , $ includeSchemaReflection );
86
+
87
+ /** @var \Cake\Database\Driver $driver */
88
+ $ driver ->setLogger ($ logger );
89
+
90
+ static ::$ _loggers [] = $ logger ;
78
91
}
79
92
80
93
/**
@@ -88,7 +101,7 @@ public function data(): array
88
101
'tables ' => array_map (function (Table $ table ) {
89
102
return $ table ->getAlias ();
90
103
}, $ this ->getTableLocator ()->genericInstances ()),
91
- 'loggers ' => $ this -> _loggers ,
104
+ 'loggers ' => static :: $ _loggers ,
92
105
];
93
106
}
94
107
@@ -100,7 +113,7 @@ public function data(): array
100
113
public function summary (): string
101
114
{
102
115
$ count = $ time = 0 ;
103
- foreach ($ this -> _loggers as $ logger ) {
116
+ foreach (static :: $ _loggers as $ logger ) {
104
117
$ count += count ($ logger ->queries ());
105
118
$ time += $ logger ->totalTime ();
106
119
}
0 commit comments