Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Napoli <matthieu@mnapoli.fr>2014-11-28 05:04:19 +0300
committerMatthieu Napoli <matthieu@mnapoli.fr>2014-11-28 05:04:19 +0300
commitf2b4a2027a2d66363db7cd49de7cbcc660d121f6 (patch)
treeb3e22d99a300ea039a58070bb8dbee6c3e1d3821 /core/Log.php
parenteff26ce0ff36d85e83803394525df0ad7a16b204 (diff)
#6622 Logger refactoring: moved the database writer to a dedicated class
Diffstat (limited to 'core/Log.php')
-rw-r--r--core/Log.php60
1 files changed, 4 insertions, 56 deletions
diff --git a/core/Log.php b/core/Log.php
index 14bf703d46..5b1d41c20a 100644
--- a/core/Log.php
+++ b/core/Log.php
@@ -4,12 +4,13 @@
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- *
*/
+
namespace Piwik;
use Piwik\Container\StaticContainer;
use Piwik\Db;
+use Piwik\Log\DatabaseBackend;
use Piwik\Log\FileBackend;
use Piwik\Log\ScreenBackend;
@@ -333,7 +334,8 @@ class Log extends Singleton
$writers['file'] = new FileBackend($this->logMessageFormat, $this->logToFilePath);
$writers['screen'] = new ScreenBackend($this->logMessageFormat);
- $writers['database'] = array($this, 'logToDatabase');
+ $writers['database'] = new DatabaseBackend($this->logMessageFormat);
+
return $writers;
}
@@ -347,19 +349,6 @@ class Log extends Singleton
return $this->currentLogLevel;
}
- private function logToDatabase($level, $tag, $datetime, $message)
- {
- $message = $this->getMessageFormattedDatabase($level, $tag, $datetime, $message);
- if (empty($message)) {
- return;
- }
-
- $sql = "INSERT INTO " . Common::prefixTable('logger_message')
- . " (tag, timestamp, level, message)"
- . " VALUES (?, ?, ?, ?)";
- Db::query($sql, array($tag, $datetime, self::getStringLevel($level), (string)$message));
- }
-
private function doLog($level, $message, $sprintfParams = array())
{
if (!$this->shouldLoggerLog($level)) {
@@ -462,45 +451,4 @@ class Log extends Singleton
$fe = fopen('php://stderr', 'w');
fwrite($fe, $message);
}
-
- /**
- * @param $level
- * @param $tag
- * @param $datetime
- * @param $message
- * @return string
- */
- private function getMessageFormattedDatabase($level, $tag, $datetime, $message)
- {
- if (is_string($message)) {
- $message = $this->formatMessage($level, $tag, $datetime, $message);
- } else {
- $logger = $this;
-
- /**
- * Triggered when trying to log an object to a database table. Plugins can use
- * this event to convert objects to strings before they are logged.
- *
- * **Example**
- *
- * public function formatDatabaseMessage(&$message, $level, $tag, $datetime, $logger) {
- * if ($message instanceof MyCustomDebugInfo) {
- * $message = $message->formatForDatabase();
- * }
- * }
- *
- * @param mixed &$message The object that is being logged. Event handlers should
- * check if the object is of a certain type and if it is,
- * set `$message` to the string that should be logged.
- * @param int $level The log level used with this log entry.
- * @param string $tag The current plugin that started logging (or if no plugin,
- * the current class).
- * @param string $datetime Datetime of the logging call.
- * @param Log $logger The Log singleton.
- */
- Piwik::postEvent(self::FORMAT_DATABASE_MESSAGE_EVENT, array(&$message, $level, $tag, $datetime, $logger));
- }
- $message = trim($message);
- return $message;
- }
}