Skip to content

Commit f3a5a90

Browse files
committed
Moved logger initialization logic out of the constructor in LoggerProxy
1 parent 09904a6 commit f3a5a90

File tree

1 file changed

+57
-18
lines changed

1 file changed

+57
-18
lines changed

lib/internal/Magento/Framework/DB/Logger/LoggerProxy.php

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,36 @@ class LoggerProxy implements LoggerInterface
4949
*/
5050
private $logger;
5151

52+
/**
53+
* @var FileFactory
54+
*/
55+
private $fileFactory;
56+
57+
/**
58+
* @var QuietFactory
59+
*/
60+
private $quietFactory;
61+
62+
/**
63+
* @var bool
64+
*/
65+
private $loggerAlias;
66+
67+
/**
68+
* @var bool
69+
*/
70+
private $logAllQueries;
71+
72+
/**
73+
* @var float
74+
*/
75+
private $logQueryTime;
76+
77+
/**
78+
* @var bool
79+
*/
80+
private $logCallStack;
81+
5282
/**
5383
* LoggerProxy constructor.
5484
* @param FileFactory $fileFactory
@@ -66,27 +96,36 @@ public function __construct(
6696
$logQueryTime = 0.001,
6797
$logCallStack = true
6898
) {
69-
switch ($loggerAlias) {
70-
case self::LOGGER_ALIAS_FILE:
71-
$this->logger = $fileFactory->create(
72-
[
73-
'logAllQueries' => $logAllQueries,
74-
'logQueryTime' => $logQueryTime,
75-
'logCallStack' => $logCallStack,
76-
]
77-
);
78-
break;
79-
default:
80-
$this->logger = $quietFactory->create();
81-
break;
82-
}
99+
$this->fileFactory = $fileFactory;
100+
$this->quietFactory = $quietFactory;
101+
$this->loggerAlias = $loggerAlias;
102+
$this->logAllQueries = $logAllQueries;
103+
$this->logQueryTime = $logQueryTime;
104+
$this->logCallStack = $logCallStack;
83105
}
84106

85107
/**
108+
* Get logger object. Initialize if needed.
86109
* @return LoggerInterface
87110
*/
88111
public function getLogger()
89112
{
113+
if($this->logger === null) {
114+
switch ($this->loggerAlias) {
115+
case self::LOGGER_ALIAS_FILE:
116+
$this->logger = $this->fileFactory->create(
117+
[
118+
'logAllQueries' => $this->logAllQueries,
119+
'logQueryTime' => $this->logQueryTime,
120+
'logCallStack' => $this->logCallStack,
121+
]
122+
);
123+
break;
124+
default:
125+
$this->logger = $this->quietFactory->create();
126+
break;
127+
}
128+
}
90129
return $this->logger;
91130
}
92131

@@ -98,7 +137,7 @@ public function getLogger()
98137
*/
99138
public function log($str)
100139
{
101-
$this->logger->log($str);
140+
$this->getLogger()->log($str);
102141
}
103142

104143
/**
@@ -110,7 +149,7 @@ public function log($str)
110149
*/
111150
public function logStats($type, $sql, $bind = [], $result = null)
112151
{
113-
$this->logger->logStats($type, $sql, $bind, $result);
152+
$this->getLogger()->logStats($type, $sql, $bind, $result);
114153
}
115154

116155
/**
@@ -119,14 +158,14 @@ public function logStats($type, $sql, $bind = [], $result = null)
119158
*/
120159
public function critical(\Exception $exception)
121160
{
122-
$this->logger->critical($exception);
161+
$this->getLogger()->critical($exception);
123162
}
124163

125164
/**
126165
* @return void
127166
*/
128167
public function startTimer()
129168
{
130-
$this->logger->startTimer();
169+
$this->getLogger()->startTimer();
131170
}
132171
}

0 commit comments

Comments
 (0)