diff options
-rw-r--r-- | core/Log.php | 5 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/Core/LogTest.php | 23 |
2 files changed, 23 insertions, 5 deletions
diff --git a/core/Log.php b/core/Log.php index 54b96a8302..a860dd1989 100644 --- a/core/Log.php +++ b/core/Log.php @@ -256,7 +256,7 @@ class Log extends Singleton { return str_replace( array("%tag%", "%message%", "%datetime%", "%level%"), - array($tag, $message, $datetime, $this->getStringLevel($level)), + array($tag, trim($message), $datetime, $this->getStringLevel($level)), $this->logMessageFormat ); } @@ -590,6 +590,7 @@ class Log extends Singleton */ Piwik::postEvent(self::FORMAT_SCREEN_MESSAGE_EVENT, array(&$message, $level, $tag, $datetime, $logger)); } + $message = trim($message); return $message . "\n"; } @@ -643,6 +644,7 @@ class Log extends Singleton */ Piwik::postEvent(self::FORMAT_DATABASE_MESSAGE_EVENT, array(&$message, $level, $tag, $datetime, $logger)); } + $message = trim($message); return $message; } @@ -684,6 +686,7 @@ class Log extends Singleton Piwik::postEvent(self::FORMAT_FILE_MESSAGE_EVENT, array(&$message, $level, $tag, $datetime, $logger)); } + $message = trim($message); $message = str_replace("\n", "\n ", $message); return $message . "\n"; } diff --git a/tests/PHPUnit/Integration/Core/LogTest.php b/tests/PHPUnit/Integration/Core/LogTest.php index c06ba7028e..f7d35e451b 100644 --- a/tests/PHPUnit/Integration/Core/LogTest.php +++ b/tests/PHPUnit/Integration/Core/LogTest.php @@ -31,15 +31,14 @@ class Core_LogTest extends DatabaseTestCase 'screen' => 'dummy error message<br /> <br /> --> To temporarily debug this error further, set const PIWIK_PRINT_ERROR_BACKTRACE=true; in index.php', - 'file' => '[Core_LogTest] LogTest.php(162): dummy error message + 'file' => '[Core_LogTest] LogTest.php(161): dummy error message dummy backtrace', - 'database' => '[Core_LogTest] LogTest.php(162): dummy error message + 'database' => '[Core_LogTest] LogTest.php(161): dummy error message dummy backtrace' ); public static $expectedErrorOutput = array( - 'screen' => ' -<div style=\'word-wrap: break-word; border: 3px solid red; padding:4px; width:70%; background-color:#FFFF96;\'> + 'screen' => '<div style=\'word-wrap: break-word; border: 3px solid red; padding:4px; width:70%; background-color:#FFFF96;\'> <strong>There is an error. Please report the message (Piwik 2.0) and full backtrace in the <a href=\'?module=Proxy&action=redirect&url=http://forum.piwik.org\' target=\'_blank\'>Piwik forums</a> (please do a Search first as it might have been reported already!).<br /><br/> Unknown error (102):</strong> <em>dummy error string</em> in <strong>dummyerrorfile.php</strong> on line <strong>145</strong> @@ -203,6 +202,22 @@ dummy backtrace' $this->checkNoMessagesLogged($backend); } + /** + * @group Core + * @dataProvider getBackendsToTest + */ + public function testLogMessagesAreTrimmed($backend) + { + Config::getInstance()->log['log_writers'] = array($backend); + + ob_start(); + TestLoggingUtility::doLog(" \n ".self::TESTMESSAGE."\n\n\n \n"); + $this->screenOutput = ob_get_contents(); + ob_end_clean(); + + $this->checkBackend($backend, self::TESTMESSAGE, $formatMessage = true, $tag = 'TestPlugin'); + } + private function checkBackend($backend, $expectedMessage, $formatMessage = false, $tag = false) { if ($formatMessage) { |