Permalink
Browse files

add ndc and mdc logging to the bundle

  • Loading branch information...
1 parent 8b3f57f commit 9ed9755009d213bdc158ffda4afaaba7baa43feb Florian Semm committed Apr 1, 2012
Showing with 145 additions and 6 deletions.
  1. +19 −0 ApplicationLoggerInterface.php
  2. +23 −5 Logger.php
  3. +1 −1 Wrapper/{Log4PhpWrapper.php → Logger.php}
  4. +33 −0 Wrapper/LoggerMDC.php
  5. +69 −0 Wrapper/LoggerNDC.php
@@ -0,0 +1,19 @@
+<?php
+namespace FS\Log4PhpBundle;
+
+use Symfony\Component\HttpKernel\Log\LoggerInterface;
+
+interface ApplicationLoggerInterface extends LoggerInterface {
+
+ /**
+ * @return \LoggerNDC
+ */
+ public function getLoggerMDC();
+
+ /**
+ * @return \LoggerMDC
+ */
+ public function getLoggerNDC();
+}
+
+?>
View
@@ -1,15 +1,19 @@
<?php
namespace FS\Log4PhpBundle;
+use FS\Log4PhpBundle\Wrapper\LoggerMDC;
+
+use FS\Log4PhpBundle\Wrapper\LoggerNDC;
+
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
-use FS\Log4PhpBundle\Wrapper\Log4PhpWrapper;
+use FS\Log4PhpBundle\Wrapper\Logger as Log4phpLogger;
/**
*
* @author Florian Semm
*/
-class Logger implements LoggerInterface {
+class Logger implements ApplicationLoggerInterface {
/**
*
* @var LoggerRoot
@@ -29,9 +33,9 @@ public function __construct($container) {
}
public function configureLogger(array $config) {
- Log4PhpWrapper::configure($config, 'LoggerConfiguratorPhp');
+ Log4phpLogger::configure($config, 'LoggerConfiguratorPhp');
- $this->logger = Log4PhpWrapper::getRootLogger();
+ $this->logger = Log4phpLogger::getRootLogger();
}
/**
@@ -43,13 +47,27 @@ private function getLogger(array $context = array()) {
$logger = $this->logger;
if (array_key_exists('app', $context)) {
- $logger = Log4PhpWrapper::getLogger($context['app']);
+ $logger = Log4phpLogger::getLogger($context['app']);
}
return $logger;
}
/**
+ * @return LoggerMDC
+ */
+ public function getLoggerMDC() {
+ return new LoggerMDC();
+ }
+
+ /**
+ * @return LoggerNDC
+ */
+ public function getLoggerNDC() {
+ return new LoggerNDC();
+ }
+
+ /**
*
* @param string $appenderName
* @param string $logger
@@ -7,7 +7,7 @@
*
* @author Florian Semm
*/
-class Log4PhpWrapper extends \Logger {
+class Logger extends \Logger {
}
View
@@ -0,0 +1,33 @@
+<?php
+namespace FS\Log4PhpBundle\Wrapper;
+
+/**
+ *
+ * @author Florian Semm
+ *
+ */
+class LoggerMDC {
+
+ /**
+ * @see \LoggerMDC::put()
+ */
+ public function put($key, $value) {
+ \LoggerMDC::put($key, $value);
+ }
+
+ /**
+ * @see \LoggerMDC:get()
+ */
+ public function get($key) {
+ return \LoggerMDC::get($key);
+ }
+
+ /**
+ * @see \LoggerMDC::remove()
+ */
+ public function remove($key) {
+ \LoggerMDC::remove($key);
+ }
+}
+
+?>
View
@@ -0,0 +1,69 @@
+<?php
+namespace FS\Log4PhpBundle\Wrapper;
+
+/**
+ *
+ * @author Florian Semm
+ *
+ */
+class LoggerNDC {
+
+ /* (non-PHPdoc)
+ * @see LoggerNDC::clear()
+ */
+ public function clear() {
+ \LoggerNDC::clear();
+ }
+
+ /* (non-PHPdoc)
+ * @see LoggerNDC::get()
+ */
+ public function get() {
+ return \LoggerNDC::get();
+ }
+
+ /* (non-PHPdoc)
+ * @see LoggerNDC::getDepth()
+ */
+ public function getDepth() {
+ return \LoggerNDC::getDepth();
+
+ }
+
+ /* (non-PHPdoc)
+ * @see LoggerNDC::peek()
+ */
+ public function peek() {
+ return \LoggerNDC::peek();
+ }
+
+ /* (non-PHPdoc)
+ * @see LoggerNDC::pop()
+ */
+ public function pop() {
+ return \LoggerNDC::pop();
+ }
+
+ /* (non-PHPdoc)
+ * @see LoggerNDC::push()
+ */
+ public function push($message) {
+ \LoggerNDC::push($message);
+ }
+
+ /* (non-PHPdoc)
+ * @see LoggerNDC::remove()
+ */
+ public function remove() {
+ \LoggerNDC::remove();
+ }
+
+ /* (non-PHPdoc)
+ * @see LoggerNDC::setMaxDepth()
+ */
+ public static function setMaxDepth($maxDepth) {
+ \LoggerNDC::setMaxDepth($maxDepth);
+ }
+}
+
+?>

0 comments on commit 9ed9755

Please sign in to comment.