From d6533762daa330394f82f414d21682a5ba217ba3 Mon Sep 17 00:00:00 2001
From: mattab <matthieu.aubry@gmail.com>
Date: Tue, 1 Oct 2013 14:33:08 +1300
Subject: [PATCH] Refs #4133 Fixing Logger and tests

---
 core/Config.php                | 2 +-
 core/Log.php                   | 8 +++++---
 tests/PHPUnit/Core/LogTest.php | 8 +++++---
 tests/index.php                | 2 +-
 4 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/core/Config.php b/core/Config.php
index 3487357a30..5d5a9c3828 100644
--- a/core/Config.php
+++ b/core/Config.php
@@ -109,6 +109,7 @@ class Config
         }
 
         $this->init();
+
         if (isset($this->configGlobal['database_tests'])
             || isset($this->configLocal['database_tests'])
         ) {
@@ -223,7 +224,6 @@ class Config
      */
     public function init()
     {
-        $this->clear();
         $this->initialized = true;
         $reportError = !empty($GLOBALS['PIWIK_TRACKER_MODE']);
 
diff --git a/core/Log.php b/core/Log.php
index 050b36a2cf..3ef721272c 100644
--- a/core/Log.php
+++ b/core/Log.php
@@ -133,7 +133,7 @@ class Log
      * 
      * @var string
      */
-    private $logMessageFormat = "[%tag%%datetime%] %message%";
+    private $logMessageFormat = "%tag%[%datetime%] %message%";
 
     /**
      * If we're logging to a file, this is the path to the file to log to.
@@ -236,7 +236,6 @@ class Log
      */
     public function formatMessage($level, $tag, $datetime, $message)
     {
-        $tag = $tag ? $tag . ':' : '';
         return str_replace(
             array("%tag%", "%message%", "%datetime%", "%level%"),
             array($tag, $message, $datetime, $this->getStringLevel($level)),
@@ -332,7 +331,10 @@ class Log
         }
 
         if (is_string($message)) {
-            $message = '[' . $currentRequestKey . '] ' . $message;
+            if(!defined('PIWIK_TEST_MODE')
+                || !PIWIK_TEST_MODE) {
+                $message = '[' . $currentRequestKey . '] ' . $message;
+            }
             $message = $this->formatMessage($level, $tag, $datetime, $message);
 
             if(!Common::isPhpCliMode()) {
diff --git a/tests/PHPUnit/Core/LogTest.php b/tests/PHPUnit/Core/LogTest.php
index e3c3cde4ae..607e99fbee 100644
--- a/tests/PHPUnit/Core/LogTest.php
+++ b/tests/PHPUnit/Core/LogTest.php
@@ -187,6 +187,7 @@ dummy backtrace'
     public function testLogMessagesIgnoredWhenNotWithinLevel($backend)
     {
         Config::getInstance()->log['log_writers'] = array($backend);
+        Config::getInstance()->log['log_level'] = 'ERROR';
 
         ob_start();
         Log::info(self::TESTMESSAGE);
@@ -203,13 +204,14 @@ dummy backtrace'
         }
 
         if ($backend == 'screen') {
-            if ($formatMessage) {
+            if ($formatMessage
+                && !Common::isPhpCliMode()) {
                 $expectedMessage = '<pre>' . $expectedMessage . '</pre>';
             }
 
             $this->screenOutput = $this->removePathsFromBacktrace($this->screenOutput);
 
-            $this->assertEquals($expectedMessage . "\n", $this->screenOutput);
+            $this->assertEquals($expectedMessage . "\n", $this->screenOutput, "unexpected output: ".$this->screenOutput);
         } else if ($backend == 'file') {
             $this->assertTrue(file_exists(self::getLogFileLocation()));
 
@@ -237,7 +239,7 @@ dummy backtrace'
     private function checkNoMessagesLogged($backend)
     {
         if ($backend == 'screen') {
-            $this->assertEmpty($this->screenOutput);
+            $this->assertEmpty($this->screenOutput, "Output not empty: ".$this->screenOutput);
         } else if ($backend == 'file') {
             $this->assertFalse(file_exists(self::getLogFileLocation()));
         } else if ($backend == 'database') {
diff --git a/tests/index.php b/tests/index.php
index c5acf9d64d..3cbf2fdd11 100644
--- a/tests/index.php
+++ b/tests/index.php
@@ -31,7 +31,7 @@
 </ul>
 </p>
 
-<p>If you are new to the wonderful world of testing, <a href='README.txt'>see the README</a> for an introduction.</p>
+<p>If you are new to the wonderful world of testing, <a href='https://github.com/piwik/piwik/blob/master/tests/README.md'>see the README</a> for an introduction.</p>
 
 <img src='resources/disturbing-image.jpg' alt='I find your lack of tests disturbing'>
 <br/><i><a href='http://www.flickr.com/photos/sebastian_bergmann/2282734669/'>Photo source & license</a></i>
-- 
GitLab