diff options
author | Benaka Moorthi <benaka.moorthi@gmail.com> | 2013-09-26 11:57:41 +0400 |
---|---|---|
committer | Benaka Moorthi <benaka.moorthi@gmail.com> | 2013-09-26 11:57:41 +0400 |
commit | b4c557e87de22cd49e041898707f7622ef57e825 (patch) | |
tree | 069f83c801a128d4a3ff897f61b2e9b95dbff84b /core | |
parent | 30002d635b7569d11c9e14675a69d5169c514064 (diff) |
Finished more.
Diffstat (limited to 'core')
-rw-r--r-- | core/Db/Schema/Myisam.php | 1 | ||||
-rw-r--r-- | core/Error.php | 8 | ||||
-rw-r--r-- | core/ExceptionHandler.php | 3 | ||||
-rw-r--r-- | core/Log.php | 70 | ||||
-rw-r--r-- | core/Piwik.php | 2 | ||||
-rw-r--r-- | core/Plugin.php | 14 | ||||
-rw-r--r-- | core/Updates/2.0-a7.php | 34 | ||||
-rw-r--r-- | core/Version.php | 2 |
8 files changed, 75 insertions, 59 deletions
diff --git a/core/Db/Schema/Myisam.php b/core/Db/Schema/Myisam.php index 58430ff071..21f9535eef 100644 --- a/core/Db/Schema/Myisam.php +++ b/core/Db/Schema/Myisam.php @@ -127,6 +127,7 @@ class Myisam implements SchemaInterface 'logger_message' => "CREATE TABLE {$prefixTables}logger_message ( idlogger_message INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, + plugin VARCHAR(50) NULL, timestamp TIMESTAMP NULL, message TEXT NULL, PRIMARY KEY(idlogger_message) diff --git a/core/Error.php b/core/Error.php index d31ff36de8..684d951859 100644 --- a/core/Error.php +++ b/core/Error.php @@ -96,7 +96,7 @@ class Error public static function formatFileAndDBLogMessage(&$message, $level, $pluginName, $datetime, $log) { if ($message instanceof Error) { - $message = $message->$errfile . '(' . $message->errline . '): ' . $message->getErrNoString() + $message = $message->errfile . '(' . $message->errline . '): ' . $message->getErrNoString() . ' - ' . $message->errstr . "\n" . $message->backtrace; $message = $log->formatMessage($level, $pluginName, $datetime, $message); @@ -153,8 +153,6 @@ class Error return; } - $plugin = 'unknown'; - $backtrace = ''; $bt = @debug_backtrace(); if ($bt !== null && isset($bt[0])) { @@ -167,12 +165,10 @@ class Error . (isset($debug['file']) ? $debug['file'] : '') . ':' . (isset($debug['line']) ? $debug['line'] : '') . ']' . "\n"; } - - $plugin = Plugin::getPluginNameFromBacktrace($bt); } $error = new Error($errno, $errstr, $errfile, $errline, $backtrace); - Log::e($plugin, $error); + Log::error($error); switch ($errno) { case E_ERROR: diff --git a/core/ExceptionHandler.php b/core/ExceptionHandler.php index 62b0bd2a77..cc25f3b989 100644 --- a/core/ExceptionHandler.php +++ b/core/ExceptionHandler.php @@ -56,8 +56,7 @@ class ExceptionHandler public static function exceptionHandler(Exception $exception) { - $plugin = Plugin::getPluginNameFromBacktrace($exception->getTrace()); - Log::e($plugin, $exception); + Log::error($exception); // TODO: what about this code? /*if (FrontController::shouldRethrowException()) { diff --git a/core/Log.php b/core/Log.php index e98ac5e6fe..42d967bbdb 100644 --- a/core/Log.php +++ b/core/Log.php @@ -30,7 +30,6 @@ class Log const LOG_LEVEL_CONFIG_OPTION = 'log_level'; const LOG_WRITERS_CONFIG_OPTION = 'log_writers'; const LOGGER_FILE_PATH_CONFIG_OPTION = 'logger_file_path'; - const LOGGER_DATABASE_TABLE_CONFIG_OPTION = 'logger_db_table'; /** * TODO @@ -55,7 +54,7 @@ class Log /** * TODO */ - public static function getInstance() + private static function getInstance() { if (self::$instance === null) { self::$instance = new Log(); @@ -81,11 +80,6 @@ class Log /** * TODO */ - private $logToDatabaseTable = "logger_message"; - - /** - * TODO - */ private $logToFileFilename; /** @@ -94,15 +88,14 @@ class Log private $loggingToScreen; /** - * TODO + * Constructor. */ - public function __construct() + private function __construct() { $logConfig = Config::getInstance()->log; $this->setCurrentLogLevelFromConfig($logConfig); $this->setLogWritersFromConfig($logConfig); $this->setLogFilePathFromConfig($logConfig); - $this->setLogDatabaseTableFromConfig($logConfig); $this->disableLoggingBasedOnConfig($logConfig); } @@ -137,13 +130,6 @@ class Log } } - private function setLogDatabaseTableFromConfig($logConfig) - { - if (!empty($logConfig[self::LOGGER_DATABASE_TABLE_CONFIG_OPTION])) { - $this->logToDatabaseTable = $logConfig[self::LOGGER_DATABASE_TABLE_CONFIG_OPTION]; - } - } - private function setLogFilePathFromConfig($logConfig) { $logDir = $logConfig[self::LOGGER_FILE_PATH_CONFIG_OPTION]; @@ -171,7 +157,7 @@ class Log if (is_string($message)) { $message = $this->formatMessage($level, $pluginName, $datetime, $message); } else { - Piwik_PostEvent(self::FORMAT_FILE_MESSAGE_EVENT, array(&$message, $level, $pluginName, $datetime, $log)); + Piwik_PostEvent(self::FORMAT_FILE_MESSAGE_EVENT, array(&$message, $level, $pluginName, $datetime, $this)); } if (empty($message)) { @@ -186,7 +172,7 @@ class Log if (is_string($message)) { $message = $this->formatMessage($level, $pluginName, $datetime, $message); } else { - Piwik_PostEvent(self::FORMAT_SCREEN_MESSAGE_EVENT, array(&$message, $level, $pluginName, $datetime, $log)); + Piwik_PostEvent(self::FORMAT_SCREEN_MESSAGE_EVENT, array(&$message, $level, $pluginName, $datetime, $this)); } if (empty($message)) { @@ -201,7 +187,7 @@ class Log if (is_string($message)) { $message = $this->formatMessage($level, $pluginName, $datetime, $message); } else { - Piwik_PostEvent(self::FORMAT_DATABASE_MESSAGE_EVENT, array(&$message, $level, $pluginName, $datetime, $log)); + Piwik_PostEvent(self::FORMAT_DATABASE_MESSAGE_EVENT, array(&$message, $level, $pluginName, $datetime, $this)); } if (empty($message)) { @@ -209,22 +195,24 @@ class Log } // TODO: allow different columns - $sql = "INSERT INTO " . Common::prefixTable($this->logToDatabaseTable) + $sql = "INSERT INTO " . Common::prefixTable('logger_message') . " (plugin, time, level, message)" . " VALUES (?, ?, ?, ?)"; Db::query($sql, array($pluginName, $datetime, $level, (string)$message)); } - /** - * TODO - */ - private function doLog($level, $pluginName, $message, $sprintfParams = array()) + private function doLog($level, $message, $sprintfParams = array()) { if ($this->shouldLoggerLog($level)) { $datetime = date("Y-m-d H:i:s"); - $message = vsprintf($message, $sprintfParams); + if (is_string($message)) { + $message = vsprintf($message, $sprintfParams); + } + + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + $pluginName = Plugin::getPluginNameFromBacktrace($backtrace); - $this->writeMessage($pluginName, $message, $datetime); + $this->writeMessage($level, $pluginName, $datetime, $message); } } @@ -260,55 +248,51 @@ class Log /** * TODO */ - public static function log($level, $pluginName, $message, $sprintfParams = array()) + private static function log($level, $message /* ... */) { - self::getInstance()->doLog($level, $pluginName, $message, $sprintfParams); + self::getInstance()->doLog($level, $message, array_slice(func_get_args(), 2)); } /** * TODO */ - public static function e($pluginName, $message, $sprintfParams = array()) + public static function error($message /* ... */) { - self::log(self::ERROR, $pluginName, $message, $sprintfParams); + self::log(self::ERROR, $message, array_slice(func_get_args(), 2)); } /** * TODO */ - public static function w($pluginName, $message, $sprintfParams = array()) + public static function warning($message /* ... */) { - self::log(self::WARN, $pluginName, $message, $sprintfParams); + self::log(self::WARN, $message, array_slice(func_get_args(), 2)); } /** * TODO */ - public static function i($pluginName, $message, $sprintfParams = array()) + public static function info($message /* ... */) { - self::log(self::INFO, $pluginName, $message, $sprintfParams); + self::log(self::INFO, $message, array_slice(func_get_args(), 2)); } /** * TODO */ - public static function d($pluginName, $message, $sprintfParams = array()) + public static function debug($message /* ... */) { - self::log(self::DEBUG, $pluginName, $message, $sprintfParams); + self::log(self::DEBUG, $message, array_slice(func_get_args(), 2)); } /** * TODO */ - public static function v($pluginName, $message, $sprintfParams = array()) + public static function verbose($message /* ... */) { - self::log(self::VERBOSE, $pluginName, $message, $sprintfParams); + self::log(self::VERBOSE, $message, array_slice(func_get_args(), 2)); } - /** - * Returns if logging should work - * @return bool - */ private function shouldLoggerLog($level) { return $level <= $this->currentLogLevel; diff --git a/core/Piwik.php b/core/Piwik.php index e4d0381eb9..0d33e42a06 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -66,7 +66,7 @@ class Piwik */ static public function log($message = '') { - Log::i("none", $message); + Log::info($message); } /** diff --git a/core/Plugin.php b/core/Plugin.php index c8f48590a4..8cb13cfe74 100644 --- a/core/Plugin.php +++ b/core/Plugin.php @@ -194,17 +194,19 @@ class Plugin return $this->pluginName; } + /** + * TODO + */ public static function getPluginNameFromBacktrace($backtrace) { - $plugin = false; foreach ($backtrace as $tracepoint) { // try and discern the plugin name - if (empty($plugin)) { - if (preg_match("/^Piwik\\Plugins\\([a-z_]+)\\/", $tracepoint['class'], $matches)) { - $plugin = $matches[1]; - } + if (isset($tracepoint['class']) + && preg_match("/Piwik\\\\Plugins\\\\([a-zA-Z_0-9]+)\\\\/", $tracepoint['class'], $matches) + ) { + return $matches[1]; } } - return $plugin ?: 'unknown'; + return false; } }
\ No newline at end of file diff --git a/core/Updates/2.0-a7.php b/core/Updates/2.0-a7.php new file mode 100644 index 0000000000..0c4c64a9ca --- /dev/null +++ b/core/Updates/2.0-a7.php @@ -0,0 +1,34 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + * @category Piwik + * @package Piwik + */ +use Piwik\Common; +use Piwik\Updater; +use Piwik\Updates; + +/** + * @package Updates + */ +class Piwik_Updates_2_0_a7 extends Updates +{ + static function getSql($schema = 'Myisam') + { + return array( + // ignore existing column name error (1060) + 'ALTER TABLE ' . Common::prefixTable('logger_message') + . " ADD COLUMN plugin VARCHAR(50) NULL AFTER idlogger_message" => 1060, + ); + } + + static function update() + { + // add plugin column to logger_message table + Updater::updateDatabase(__FILE__, self::getSql()); + } +} diff --git a/core/Version.php b/core/Version.php index 172fe9daff..59f77345a8 100644 --- a/core/Version.php +++ b/core/Version.php @@ -22,5 +22,5 @@ final class Version * Current Piwik version * @var string */ - const VERSION = '2.0-a6'; + const VERSION = '2.0-a7'; } |