@@ -34,7 +34,7 @@ class SqlLogPanel extends DebugPanel
3434 *
3535 * @var array
3636 */
37- protected array $ _loggers = [];
37+ protected static array $ _loggers = [];
3838
3939 /**
4040 * Initialize hook - configures logger.
@@ -47,34 +47,47 @@ class SqlLogPanel extends DebugPanel
4747 public function initialize (): void
4848 {
4949 $ configs = ConnectionManager::configured ();
50- $ includeSchemaReflection = (bool )Configure::read ('DebugKit.includeSchemaReflection ' );
5150
5251 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 ' );
6565
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+ }
7278
73- /** @var \Cake\Database\Driver $driver */
74- $ driver ->setLogger ($ logger );
79+ if ($ logger instanceof DebugLog) {
80+ $ logger ->setIncludeSchema ($ includeSchemaReflection );
81+ static ::$ _loggers [] = $ logger ;
7582
76- $ this -> _loggers [] = $ logger ;
83+ return ;
7784 }
85+ $ logger = new DebugLog ($ logger , $ name , $ includeSchemaReflection );
86+
87+ /** @var \Cake\Database\Driver $driver */
88+ $ driver ->setLogger ($ logger );
89+
90+ static ::$ _loggers [] = $ logger ;
7891 }
7992
8093 /**
@@ -88,7 +101,7 @@ public function data(): array
88101 'tables ' => array_map (function (Table $ table ) {
89102 return $ table ->getAlias ();
90103 }, $ this ->getTableLocator ()->genericInstances ()),
91- 'loggers ' => $ this -> _loggers ,
104+ 'loggers ' => static :: $ _loggers ,
92105 ];
93106 }
94107
@@ -100,7 +113,7 @@ public function data(): array
100113 public function summary (): string
101114 {
102115 $ count = $ time = 0 ;
103- foreach ($ this -> _loggers as $ logger ) {
116+ foreach (static :: $ _loggers as $ logger ) {
104117 $ count += count ($ logger ->queries ());
105118 $ time += $ logger ->totalTime ();
106119 }
0 commit comments