Skip to content

Commit

Permalink
merged branch willdurand/propel-logger (PR #8706)
Browse files Browse the repository at this point in the history
This PR was merged into the master branch.

Discussion
----------

[Propel1] Refactor PropelLogger

* Implement `BasicLogger` interface (Propel)

Commits
-------

50435aa [Propel1] Refactor PropelLogger
  • Loading branch information
fabpot committed Aug 9, 2013
2 parents 3248c1b + 50435aa commit bcd7ab1
Showing 1 changed file with 53 additions and 46 deletions.
99 changes: 53 additions & 46 deletions src/Symfony/Bridge/Propel1/Logger/PropelLogger.php
Expand Up @@ -20,7 +20,7 @@
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author William Durand <william.durand1@gmail.com>
*/
class PropelLogger
class PropelLogger implements \BasicLogger
{
/**
* @var LoggerInterface
Expand All @@ -30,14 +30,17 @@ class PropelLogger
/**
* @var array
*/
protected $queries;
protected $queries = array();

/**
* @var Stopwatch
*/
protected $stopwatch;

private $isPrepared;
/**
* @var Boolean
*/
private $isPrepared = false;

/**
* Constructor.
Expand All @@ -48,87 +51,59 @@ class PropelLogger
public function __construct(LoggerInterface $logger = null, Stopwatch $stopwatch = null)
{
$this->logger = $logger;
$this->queries = array();
$this->stopwatch = $stopwatch;
$this->isPrepared = false;
}

/**
* A convenience function for logging an alert event.
*
* @param mixed $message the message to log.
* {@inheritDoc}
*/
public function alert($message)
{
if (null !== $this->logger) {
$this->logger->alert($message);
}
$this->log($message, 'alert');
}

/**
* A convenience function for logging a critical event.
*
* @param mixed $message the message to log.
* {@inheritDoc}
*/
public function crit($message)
{
if (null !== $this->logger) {
$this->logger->critical($message);
}
$this->log($message, 'crit');
}

/**
* A convenience function for logging an error event.
*
* @param mixed $message the message to log.
* {@inheritDoc}
*/
public function err($message)
{
if (null !== $this->logger) {
$this->logger->error($message);
}
$this->log($message, 'err');
}

/**
* A convenience function for logging a warning event.
*
* @param mixed $message the message to log.
* {@inheritDoc}
*/
public function warning($message)
{
if (null !== $this->logger) {
$this->logger->warning($message);
}
$this->log($message, 'warning');
}

/**
* A convenience function for logging an critical event.
*
* @param mixed $message the message to log.
* {@inheritDoc}
*/
public function notice($message)
{
if (null !== $this->logger) {
$this->logger->notice($message);
}
$this->log($message, 'notice');
}

/**
* A convenience function for logging an critical event.
*
* @param mixed $message the message to log.
* {@inheritDoc}
*/
public function info($message)
{
if (null !== $this->logger) {
$this->logger->info($message);
}
$this->log($message, 'info');
}

/**
* A convenience function for logging a debug event.
*
* @param mixed $message the message to log.
* {@inheritDoc}
*/
public function debug($message)
{
Expand All @@ -152,8 +127,40 @@ public function debug($message)

if ($add) {
$this->queries[] = $message;
if (null !== $this->logger) {
$this->logger->debug($message);
$this->log($message, 'debug');
}
}

/**
* {@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);
}
}
}
Expand Down

0 comments on commit bcd7ab1

Please sign in to comment.