From 1d5aedc49ab2e5d07c10e600fcd5a12a1f9ce378 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Mon, 1 Dec 2014 12:17:46 +1300 Subject: #6622 Logger refactoring: quick code simplification --- core/Log.php | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'core/Log.php') diff --git a/core/Log.php b/core/Log.php index 54844f7dbb..52123d3593 100644 --- a/core/Log.php +++ b/core/Log.php @@ -294,25 +294,13 @@ class Log extends Singleton return; } - $datetime = date("Y-m-d H:i:s"); - foreach ($this->processors as $processor) { $message = $processor($message, $sprintfParams, $level); } - if (version_compare(phpversion(), '5.3.6', '>=')) { - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); - } else { - $backtrace = debug_backtrace(); - } - $tag = Plugin::getPluginNameFromBacktrace($backtrace); - - // if we can't determine the plugin, use the name of the calling class - if ($tag == false) { - $tag = $this->getClassNameThatIsLogging($backtrace); - } + $tag = $this->getLoggingClassName(); - $this->writeMessage($level, $tag, $datetime, $message); + $this->writeMessage($level, $tag, date("Y-m-d H:i:s"), $message); } private function writeMessage($level, $tag, $datetime, $message) @@ -359,9 +347,9 @@ class Log extends Singleton { foreach ($backtrace as $tracepoint) { if (isset($tracepoint['class']) - && $tracepoint['class'] != "Piwik\\Log" - && $tracepoint['class'] != "Piwik\\Piwik" - && $tracepoint['class'] != "Piwik\\CronArchive" + && $tracepoint['class'] != 'Piwik\Log' + && $tracepoint['class'] != 'Piwik\Piwik' + && $tracepoint['class'] != 'Piwik\CronArchive' ) { return $tracepoint['class']; } @@ -381,4 +369,27 @@ class Log extends Singleton $fe = fopen('php://stderr', 'w'); fwrite($fe, $message); } + + /** + * Returns the name of the plugin/class that triggered the log. + * + * @return string + */ + private function getLoggingClassName() + { + if (version_compare(phpversion(), '5.3.6', '>=')) { + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); + } else { + $backtrace = debug_backtrace(); + } + + $tag = Plugin::getPluginNameFromBacktrace($backtrace); + + // if we can't determine the plugin, use the name of the calling class + if ($tag == false) { + $tag = $this->getClassNameThatIsLogging($backtrace); + return $tag; + } + return $tag; + } } -- cgit v1.2.3