diff options
author | Frederic Guillot <fred@kanboard.net> | 2017-10-25 16:22:10 -0700 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2017-10-25 16:22:10 -0700 |
commit | 9e2b2a32fd0e967ad3184e9a5d091a29953acb91 (patch) | |
tree | 00822e24aa1110c73ca455a8d096ef296c008cbc /vendor/fguillot/simpleLogger/src/SimpleLogger/Base.php | |
parent | c507c5416251c505cb3e088a03c6664bed73c812 (diff) |
Include composer dependencies in repo
Diffstat (limited to 'vendor/fguillot/simpleLogger/src/SimpleLogger/Base.php')
-rw-r--r-- | vendor/fguillot/simpleLogger/src/SimpleLogger/Base.php | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/vendor/fguillot/simpleLogger/src/SimpleLogger/Base.php b/vendor/fguillot/simpleLogger/src/SimpleLogger/Base.php new file mode 100644 index 00000000..c662a1a3 --- /dev/null +++ b/vendor/fguillot/simpleLogger/src/SimpleLogger/Base.php @@ -0,0 +1,89 @@ +<?php + +namespace SimpleLogger; + +use Psr\Log\AbstractLogger; +use Psr\Log\LogLevel; + +/** + * Base class for loggers + * + * @package SimpleLogger + * @author Frédéric Guillot + */ +abstract class Base extends AbstractLogger +{ + /** + * Minimum log level for the logger + * + * @access private + * @var string + */ + private $level = LogLevel::DEBUG; + + /** + * Set minimum log level + * + * @access public + * @param string $level + */ + public function setLevel($level) + { + $this->level = $level; + } + + /** + * Get minimum log level + * + * @access public + * @return string + */ + public function getLevel() + { + return $this->level; + } + + /** + * Dump to log a variable (by example an array) + * + * @param mixed $variable + */ + public function dump($variable) + { + $this->log(LogLevel::DEBUG, var_export($variable, true)); + } + + /** + * Interpolates context values into the message placeholders. + * + * @access protected + * @param string $message + * @param array $context + * @return string + */ + protected function interpolate($message, array $context = array()) + { + // build a replacement array with braces around the context keys + $replace = array(); + + foreach ($context as $key => $val) { + $replace['{' . $key . '}'] = $val; + } + + // interpolate replacement values into the message and return + return strtr($message, $replace); + } + + /** + * Format log message + * + * @param mixed $level + * @param string $message + * @param array $context + * @return string + */ + protected function formatMessage($level, $message, array $context = array()) + { + return '['.date('Y-m-d H:i:s').'] ['.$level.'] '.$this->interpolate($message, $context).PHP_EOL; + } +} |