merged branch willdurand/propel-logger (PR #8706)

This PR was merged into the master branch.

Discussion
----------

[Propel1] Refactor PropelLogger

* Implement `BasicLogger` interface (Propel)

Commits
-------

50435aa [Propel1] Refactor PropelLogger
This commit is contained in:
Fabien Potencier 2013-08-09 14:55:43 +02:00
commit bcd7ab1eae

View File

@ -20,7 +20,7 @@ use Psr\Log\LoggerInterface;
* @author Fabien Potencier <fabien.potencier@symfony-project.com> * @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author William Durand <william.durand1@gmail.com> * @author William Durand <william.durand1@gmail.com>
*/ */
class PropelLogger class PropelLogger implements \BasicLogger
{ {
/** /**
* @var LoggerInterface * @var LoggerInterface
@ -30,14 +30,17 @@ class PropelLogger
/** /**
* @var array * @var array
*/ */
protected $queries; protected $queries = array();
/** /**
* @var Stopwatch * @var Stopwatch
*/ */
protected $stopwatch; protected $stopwatch;
private $isPrepared; /**
* @var Boolean
*/
private $isPrepared = false;
/** /**
* Constructor. * Constructor.
@ -48,87 +51,59 @@ class PropelLogger
public function __construct(LoggerInterface $logger = null, Stopwatch $stopwatch = null) public function __construct(LoggerInterface $logger = null, Stopwatch $stopwatch = null)
{ {
$this->logger = $logger; $this->logger = $logger;
$this->queries = array();
$this->stopwatch = $stopwatch; $this->stopwatch = $stopwatch;
$this->isPrepared = false;
} }
/** /**
* A convenience function for logging an alert event. * {@inheritDoc}
*
* @param mixed $message the message to log.
*/ */
public function alert($message) public function alert($message)
{ {
if (null !== $this->logger) { $this->log($message, 'alert');
$this->logger->alert($message);
}
} }
/** /**
* A convenience function for logging a critical event. * {@inheritDoc}
*
* @param mixed $message the message to log.
*/ */
public function crit($message) public function crit($message)
{ {
if (null !== $this->logger) { $this->log($message, 'crit');
$this->logger->critical($message);
}
} }
/** /**
* A convenience function for logging an error event. * {@inheritDoc}
*
* @param mixed $message the message to log.
*/ */
public function err($message) public function err($message)
{ {
if (null !== $this->logger) { $this->log($message, 'err');
$this->logger->error($message);
}
} }
/** /**
* A convenience function for logging a warning event. * {@inheritDoc}
*
* @param mixed $message the message to log.
*/ */
public function warning($message) public function warning($message)
{ {
if (null !== $this->logger) { $this->log($message, 'warning');
$this->logger->warning($message);
}
} }
/** /**
* A convenience function for logging an critical event. * {@inheritDoc}
*
* @param mixed $message the message to log.
*/ */
public function notice($message) public function notice($message)
{ {
if (null !== $this->logger) { $this->log($message, 'notice');
$this->logger->notice($message);
}
} }
/** /**
* A convenience function for logging an critical event. * {@inheritDoc}
*
* @param mixed $message the message to log.
*/ */
public function info($message) public function info($message)
{ {
if (null !== $this->logger) { $this->log($message, 'info');
$this->logger->info($message);
}
} }
/** /**
* A convenience function for logging a debug event. * {@inheritDoc}
*
* @param mixed $message the message to log.
*/ */
public function debug($message) public function debug($message)
{ {
@ -152,8 +127,40 @@ class PropelLogger
if ($add) { if ($add) {
$this->queries[] = $message; $this->queries[] = $message;
if (null !== $this->logger) { $this->log($message, 'debug');
$this->logger->debug($message); }
}
/**
* {@inheritDoc}
*/
public function log($message, $severity = null)
{
if (null !== $this->logger) {
$message = is_string($message) ? $message : var_export($message, true);
switch ($severity) {
case 'alert':
$this->logger->alert($message);
break;
case 'crit':
$this->logger->critical($message);
break;
case 'err':
$this->logger->error($message);
break;
case 'warning':
$this->logger->warning($message);
break;
case 'notice':
$this->logger->notice($message);
break;
case 'info':
$this->logger->info($message);
break;
case 'debug':
default:
$this->logger->debug($message);
} }
} }
} }