diff options
author | Benaka Moorthi <benaka.moorthi@gmail.com> | 2013-09-24 08:47:14 +0400 |
---|---|---|
committer | Benaka Moorthi <benaka.moorthi@gmail.com> | 2013-09-24 08:47:14 +0400 |
commit | 2cb3bca565e0251fa7ecd74246d05f4cbdc1aa61 (patch) | |
tree | ca5a58226bac4c5917669a8945bb39c55c1f891a /core/Log.php | |
parent | 019bdb782bf33bfadc1c1a254fcd128094d0ce7e (diff) | |
parent | 463e88b27a8effea653e6bf6f3d93da8ca4906e1 (diff) |
Merge branch 'master' into log
Conflicts:
core/Log.php
Diffstat (limited to 'core/Log.php')
-rw-r--r-- | core/Log.php | 65 |
1 files changed, 43 insertions, 22 deletions
diff --git a/core/Log.php b/core/Log.php index 787cc81e92..2b83758424 100644 --- a/core/Log.php +++ b/core/Log.php @@ -13,12 +13,6 @@ namespace Piwik; use Piwik\Common; use Piwik\Db; -/* TODO: -; all calls to the API (method name, parameters, execution time, caller IP, etc.) -; disabled by default as it can cause serious overhead and should only be used wisely -;logger_api_call[] = file -*/ - /** * TODO */ @@ -41,6 +35,21 @@ class Log /** * TODO */ + const FORMAT_FILE_MESSAGE_EVENT = 'Log.formatFileMessage'; + + /** + * TODO + */ + const FORMAT_SCREEN_MESSAGE_EVENT = 'Log.formatScreenMessage'; + + /** + * TODO + */ + const FORMAT_DATABASE_MESSAGE_EVENT = 'Log.formatDatabaseMessage'; + + /** + * TODO + */ private static $instance = null; /** @@ -150,37 +159,49 @@ class Log $writer = false; if ($writerName == 'file') { - $writer = function ($level, $pluginName, $datetime, $message) use ($self) { - $self->logToFile($this->formatMessage($level, $pluginName, $datetime, $message)); - }; + $writer = array($this, 'logToFile'); } else if ($writerName == 'screen') { - $writer = function ($pluginName, $datetime, $message) use ($self) { - $self->logToScreen($this->formatMessage($level, $pluginName, $datetime, $message)); - }; + $writer = array($this, 'logToScreen'); } else if ($writerName == 'db') { - $writer = function ($level, $pluginName, $datetime, $message) use ($self) { - $self->logToDatabase($level, $pluginName, $datetime, $message); - }; + $writer = array($this, 'logToDatabase'); } return $writer; } - private function logToFile($message) + private function logToFile($level, $pluginName, $datetime, $message) { + if (is_string($message)) { + $message = $this->formatMessage($level, $pluginName, $datetime, $message); + } else { + Piwik_PostEvent(self::FORMAT_FILE_MESSAGE_EVENT, array(&$message, $level, $pluginName, $datetime)); + } + file_put_contents($this->logToFileFilename, $message . "\n", FILE_APPEND); } - private function logToScreen($message) + private function logToScreen($level, $pluginName, $datetime, $message) { + if (is_string($message)) { + $message = $this->formatMessage($level, $pluginName, $datetime, $message); + } else { + Piwik_PostEvent(self::FORMAT_SCREEN_MESSAGE_EVENT, array(&$message, $level, $pluginName, $datetime)); + } + echo $message . "\n"; } - private function logToDatabase(logToDatabase$pluginName, $datetime, $message) + private function logToDatabase($level, $pluginName, $datetime, $message) { + if (is_string($message)) { + $message = $this->formatMessage($level, $pluginName, $datetime, $message); + } else { + Piwik_PostEvent(self::FORMAT_DATABASE_MESSAGE_EVENT, array(&$message, $level, $pluginName, $datetime)); + } + $sql = "INSERT INTO " . Common::prefixTable($this->logToDatabaseTable) . " (plugin, time, level, message)" . " VALUES (?, ?, ?, ?)"; - Db::query($sql, array($pluginName, $datetime, $level, $message)); + Db::query($sql, array($pluginName, $datetime, $level, (string)$message)); } /** @@ -221,7 +242,7 @@ class Log if ($level == self::ERROR && !$this->loggingToScreen ) { - $this->logToScreen($this->formatMessage($level, $pluginName, $datetime, $message)); + $this->logToScreen($level, $pluginName, $datetime, $message); } } @@ -305,7 +326,7 @@ class Log private function getLogLevelFromStringName($name) { - switch ($name) { + switch (strtoupper($name)) { case 'NONE': return self::NONE; case 'ERROR': @@ -335,4 +356,4 @@ class Log ); return $levelToName[$level]; } -}
\ No newline at end of file +} |