From 299198f7181fccf1e9a684649d173a1ebbdfbd1e Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Mon, 5 Mar 2018 12:04:28 -0800 Subject: Move SimpleLogger lib into app source tree --- app/Core/Log/Base.php | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 app/Core/Log/Base.php (limited to 'app/Core/Log/Base.php') diff --git a/app/Core/Log/Base.php b/app/Core/Log/Base.php new file mode 100644 index 00000000..3c3c8485 --- /dev/null +++ b/app/Core/Log/Base.php @@ -0,0 +1,89 @@ +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; + } +} -- cgit v1.2.3