Permalink
Browse files

[Monolog] Added ServiceContainer::getLogger().

- Seldaek/monolog is now a dependency
- The service container has the ability to contain several loggers (one per datasource)
- A fallback mechanism allows to keep only one logger
  • Loading branch information...
1 parent 93217aa commit da7249d60b9362a425518fda11a91e647dd3966a @fzaninotto fzaninotto committed Dec 11, 2011
View
@@ -19,6 +19,7 @@ if (file_exists($file = __DIR__.'/vendor/.composer/autoload.php')) {
'Propel\Runtime' => __DIR__ . '/src',
'Propel\Generator' => __DIR__ . '/src',
'Symfony\Component' => __DIR__ . '/vendor',
+ 'Monolog' => __DIR__ . '/vendor/Monolog/src/',
'Foo' => __DIR__ . '/tests/Fixtures/namespaced/build/classes',
'Baz' => __DIR__ . '/tests/Fixtures/namespaced/build/classes',
'Propel\Tests' => array(
@@ -28,4 +29,4 @@ if (file_exists($file = __DIR__.'/vendor/.composer/autoload.php')) {
),
));
$loader->register();
-}
+}
View
@@ -19,7 +19,8 @@
"require": {
"php": ">=5.3.2",
"symfony/yaml": ">=2.0",
- "symfony/console": ">=2.0"
+ "symfony/console": ">=2.0",
+ "Seldaek/monolog": ">=1.0.2"
},
"autoload": {
"psr-0": {
@@ -29,4 +30,4 @@
"bin": [
"bin/propel"
]
-}
+}
@@ -1,82 +0,0 @@
-<?php
-
-/**
- * This file is part of the Propel package.
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- *
- * @license MIT License
- */
-
-namespace Propel\Runtime\Logger;
-
-/**
- * This is a minimalistic interface that any logging class must implement for Propel.
- *
- * The API for this interface is based on the PEAR::Log interface. It provides a simple
- * API that can be used by Propel independently of Log backend.
- *
- * PEAR::Log and perhaps the Log API was developed by Chuck Hagenbuch <chuck@horde.org>
- * and Jon Parise <jon@php.net>.
- *
- * @author Hans Lellelid <hans@xmpl.org>
- */
-interface BasicLogger
-{
-
- /**
- * A convenience function for logging an alert event.
- *
- * @param mixed $message String or Exception object containing the message to log.
- */
- public function alert($message);
-
- /**
- * A convenience function for logging a critical event.
- *
- * @param mixed $message String or Exception object containing the message to log.
- */
- public function crit($message);
-
- /**
- * A convenience function for logging an error event.
- *
- * @param mixed $message String or Exception object containing the message to log.
- */
- public function err($message);
-
- /**
- * A convenience function for logging a warning event.
- *
- * @param mixed $message String or Exception object containing the message to log.
- */
- public function warning($message);
- /**
- * A convenience function for logging an critical event.
- *
- * @param mixed $message String or Exception object containing the message to log.
- */
- public function notice($message);
- /**
- * A convenience function for logging an critical event.
- *
- * @param mixed $message String or Exception object containing the message to log.
- */
- public function info($message);
-
- /**
- * A convenience function for logging a debug event.
- *
- * @param mixed $message String or Exception object containing the message to log.
- */
- public function debug($message);
-
- /**
- * Primary method to handle logging.
- *
- * @param mixed $message String or Exception object containing the message to log.
- * @param int $severity The numeric severity. Defaults to null so that no
- * assumptions are made about the logging backend.
- */
- public function log($message, $severity = null);
-}
@@ -1,151 +0,0 @@
-<?php
-
-/**
- * This file is part of the Propel package.
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- *
- * @license MIT License
- */
-
-namespace Propel\Runtime\Logger;
-
-/**
- * Mojavi logging adapter for propel
- *
- * @author Brandon Keepers <brandon@opensoul.org>
- */
-class MojaviLogAdapter implements BasicLogger
-{
- /**
- * Instance of mojavi logger
- */
- private $logger = null;
-
- /**
- * constructor for setting up Mojavi log adapter
- *
- * @param ErrorLog $logger Instance of Mojavi error log obtained by
- * calling LogManager::getLogger();
- */
- public function __construct($logger = null)
- {
- $this->logger = $logger;
- }
-
- /**
- * A convenience function for logging an alert event.
- *
- * @param mixed $message String or Exception object containing the message to log.
- */
- public function alert($message)
- {
- $this->log($message, 'alert');
- }
-
- /**
- * A convenience function for logging a critical event.
- *
- * @param mixed $message String or Exception object containing the message to log.
- */
- public function crit($message)
- {
- $this->log($message, 'crit');
- }
-
- /**
- * A convenience function for logging an error event.
- *
- * @param mixed $message String or Exception object containing the message to log.
- */
- public function err($message)
- {
- $this->log($message, 'err');
- }
-
- /**
- * A convenience function for logging a warning event.
- *
- * @param mixed $message String or Exception object containing the message to log.
- */
- public function warning($message)
- {
- $this->log($message, 'warning');
- }
-
-
- /**
- * A convenience function for logging an critical event.
- *
- * @param mixed $message String or Exception object containing the message to log.
- */
- public function notice($message)
- {
- $this->log($message, 'notice');
- }
- /**
- * A convenience function for logging an critical event.
- *
- * @param mixed $message String or Exception object containing the message to log.
- */
- public function info($message)
- {
- $this->log($message, 'info');
- }
-
- /**
- * A convenience function for logging a debug event.
- *
- * @param mixed $message String or Exception object containing the message to log.
- */
- public function debug($message)
- {
- $this->log($message, 'debug');
- }
-
- /**
- * Primary method to handle logging.
- *
- * @param mixed $message String or Exception object containing the message to log.
- * @param integer $severity The numeric severity. Defaults to null so that no
- * assumptions are made about the logging backend.
- */
- public function log($message, $severity = null)
- {
- if (is_null($this->logger))
- $this->logger = LogManager::getLogger('propel');
-
- switch($severity)
- {
- case 'crit':
- $method = 'fatal';
- break;
- case 'err':
- $method = 'error';
- break;
- case 'alert':
- case 'warning':
- $method = 'warning';
- break;
- case 'notice':
- case 'info':
- $method = 'info';
- break;
- case 'debug':
- default:
- $method = 'debug';
- }
-
- // get a backtrace to pass class, function, file, & line to Mojavi logger
- $trace = debug_backtrace();
-
- // call the appropriate Mojavi logger method
- $this->logger->{$method} (
- $message,
- $trace[2]['class'],
- $trace[2]['function'],
- $trace[1]['file'],
- $trace[1]['line']
- );
- }
-}
@@ -127,4 +127,18 @@ function getReadConnection($name);
* @return \Propel\Runtime\Util\Profiler.
*/
function getProfiler();
+
+ /**
+ * Check if a logger is available for a given datasource.
+ *
+ * @return boolean
+ */
+ function hasLogger($name = 'defaultLogger');
+
+ /**
+ * Get a logger for a given datasource, or the default logger.
+ *
+ * @return \Monolog\Logger
+ */
+ function getLogger($name = 'defaultLogger');
}
Oops, something went wrong.

0 comments on commit da7249d

Please sign in to comment.