summaryrefslogtreecommitdiff
path: root/vendor/fguillot/simpleLogger/src/SimpleLogger/Logger.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2017-10-25 16:22:10 -0700
committerFrederic Guillot <fred@kanboard.net>2017-10-25 16:22:10 -0700
commit9e2b2a32fd0e967ad3184e9a5d091a29953acb91 (patch)
tree00822e24aa1110c73ca455a8d096ef296c008cbc /vendor/fguillot/simpleLogger/src/SimpleLogger/Logger.php
parentc507c5416251c505cb3e088a03c6664bed73c812 (diff)
Include composer dependencies in repo
Diffstat (limited to 'vendor/fguillot/simpleLogger/src/SimpleLogger/Logger.php')
-rw-r--r--vendor/fguillot/simpleLogger/src/SimpleLogger/Logger.php94
1 files changed, 94 insertions, 0 deletions
diff --git a/vendor/fguillot/simpleLogger/src/SimpleLogger/Logger.php b/vendor/fguillot/simpleLogger/src/SimpleLogger/Logger.php
new file mode 100644
index 00000000..dc340cde
--- /dev/null
+++ b/vendor/fguillot/simpleLogger/src/SimpleLogger/Logger.php
@@ -0,0 +1,94 @@
+<?php
+
+namespace SimpleLogger;
+
+use Psr\Log\AbstractLogger;
+use Psr\Log\LoggerAwareInterface;
+use Psr\Log\LoggerInterface;
+use Psr\Log\LogLevel;
+
+/**
+ * Handler for multiple loggers
+ *
+ * @package SimpleLogger
+ * @author Frédéric Guillot
+ */
+class Logger extends AbstractLogger implements LoggerAwareInterface
+{
+ /**
+ * Logger instances
+ *
+ * @access private
+ */
+ private $loggers = array();
+
+ /**
+ * Get level priority
+ *
+ * @param mixed $level
+ * @return integer
+ */
+ public function getLevelPriority($level)
+ {
+ switch ($level) {
+ case LogLevel::EMERGENCY:
+ return 600;
+ case LogLevel::ALERT:
+ return 550;
+ case LogLevel::CRITICAL:
+ return 500;
+ case LogLevel::ERROR:
+ return 400;
+ case LogLevel::WARNING:
+ return 300;
+ case LogLevel::NOTICE:
+ return 250;
+ case LogLevel::INFO:
+ return 200;
+ }
+
+ return 100;
+ }
+
+ /**
+ * Sets a logger instance on the object
+ *
+ * @param LoggerInterface $logger
+ * @return null
+ */
+ public function setLogger(LoggerInterface $logger)
+ {
+ $this->loggers[] = $logger;
+ }
+
+ /**
+ * Proxy method to the real loggers
+ *
+ * @param mixed $level
+ * @param string $message
+ * @param array $context
+ * @return null
+ */
+ public function log($level, $message, array $context = array())
+ {
+ foreach ($this->loggers as $logger) {
+ if ($this->getLevelPriority($level) >= $this->getLevelPriority($logger->getLevel())) {
+ $logger->log($level, $message, $context);
+ }
+ }
+ }
+
+ /**
+ * Dump variables for debugging
+ *
+ * @param mixed $variable
+ */
+ public function dump($variable)
+ {
+ foreach ($this->loggers as $logger) {
+ if ($this->getLevelPriority(LogLevel::DEBUG) >= $this->getLevelPriority($logger->getLevel())) {
+ $logger->dump($variable);
+ }
+ }
+ }
+}