8000 [Propel1] Refactor PropelLogger · daifma/symfony@50435aa · GitHub
[go: up one dir, main page]

Skip to content

Commit 50435aa

Browse files
committed
[Propel1] Refactor PropelLogger
Implement BasicLogger interface (Propel)
1 parent 728d194 commit 50435aa

File tree

1 file changed

+53
-46
lines changed

1 file changed

+53
-46
lines changed

src/Symfony/Bridge/Propel1/Logger/PropelLogger.php

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
2121
* @author William Durand <william.durand1@gmail.com>
2222
*/
23-
class PropelLogger
23+
class PropelLogger implements \BasicLogger
2424
{
2525
/**
2626
* @var LoggerInterface
@@ -30,14 +30,17 @@ class PropelLogger
3030
/**
3131
* @var array
3232
*/
33-
protected $queries;
33+
protected $queries = array();
3434

3535
/**
3636
* @var Stopwatch
3737
*/
3838
protected $stopwatch;
3939

40-
private $isPrepared;
40+
/**
41+
* @var Boolean
42+
*/
43+
private $isPrepared = false;
4144

4245
/**
4346
* Constructor.
@@ -48,87 +51,59 @@ class PropelLogger
4851
public function __construct(LoggerInterface $logger = null, Stopwatch $stopwatch = null)
4952
{
5053
$this->logger = $logger;
51-
$this->queries = array();
5254
$this->stopwatch = $stopwatch;
53-
$this->isPrepared = false;
5455
}
5556

5657
/**
57-
* A convenience function for logging an alert event.
58-
*
59-
* @param mixed $message the message to log.
58+
* {@inheritDoc}
6059
*/
6160
public function alert($message)
6261
{
63-
if (null !== $this->logger) {
64-
$this->logger->alert($message);
65-
}
62+
$this->log($message, 'alert');
6663
}
6764

6865
/**
69-
* A convenience function for logging a critical event.
70-
*
71-
* @param mixed $message the message to log.
66+
* {@inheritDoc}
7267
*/
7368
public function crit($message)
7469
{
75-
if (null !== $this->logger) {
76-
$this->logger->critical($message);
77-
}
70+
$this->log($message, 'crit');
7871
}
7972

8073
/**
81-
* A convenience function for logging an error event.
82-
*
83-
* @param mixed $message the message to log.
74+
* {@inheritDoc}
8475
*/
8576
public function err($message)
8677
{
87-
if (null !== $this->logger) {
88-
$this->logger->error($message);
89-
}
78+
$this->log($message, 'err');
9079
}
9180

9281
/**
93-
* A convenience function for logging a warning event.
94-
*
95-
* @param mixed $message the message to log.
82+
* {@inheritDoc}
9683
*/
9784
public function warning($message)
9885
{
99-
if (null !== $this->logger) {
100-
$this->logger->warning($message);
101-
}
86+
$this->log($message, 'warning');
10287
}
10388

10489
/**
105-
* A convenience function for logging an critical event.
106-
*
107-
* @param mixed $message the message to log.
90+
* {@inheritDoc}
10891
*/
10992
public function notice($message)
11093
{
111-
if (null !== $this->logger) {
112-
$this->logger->notice($message);
113-
}
94+
$this->log($message, 'notice');
11495
}
11596

11697
/**
117-
* A convenience function for logging an critical event.
118-
*
119-
* @param mixed $message the message to log.
98+
* {@inheritDoc}
12099
*/
121100
public function info($message)
122101
{
123-
if (null !== $this->logger) {
124-
$this->logger->info($message);
125-
}
102+
$this->log($message, 'info');
126103
}
127104

128105
/**
129-
* A convenience function for logging a debug event.
130-
*
131-
* @param mixed $message the message to log.
106+
* {@inheritDoc}
132107
*/
133108
public function debug($message)
134109
{
@@ -152,8 +127,40 @@ public function debug($message)
152127

153128
if ($add) {
154129
$this->queries[] = $message;
155-
if (null !== $this->logger) {
156-
$this->logger->debug($message);
130+
$this->log($message, 'debug');
131+
}
132+
}
133+
134+
/**
135+
* {@inheritDoc}
136+
*/
137+
public function log($message, $severity = null)
138+
{
139+
if (null !== $this->logger) {
140+
$message = is_string($message) ? $message : var_export($message, true);
141+
142+
switch ($severity) {
143+
case 'alert':
144+
$this->logger->alert($message);
145+
break;
146+
case 'crit':
147+
$this->logger->critical($message);
148+
break;
149+
case 'err':
150+
$this->logger->error($message);
151+
break;
152+
case 'warning':
153+
$this->logger->warning($message);
154+
break;
155+
case 'notice':
156+
$this->logger->notice($message);
157+
break;
158+
case 'info':
159+
$this->logger->info($message);
160+
break;
161+
case 'debug':
162+
default:
163+
$this->logger->debug($message);
157164
}
158165
}
159166
}

0 commit comments

Comments
 (0)
0