From b0307904aec996194f1c83711066994e129f61a3 Mon Sep 17 00:00:00 2001 From: nate Date: Thu, 12 Apr 2007 00:34:16 +0000 Subject: [PATCH] Fixing (moving) session string warning (Ticket #2377) and adding automatic logging code git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4846 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/bootstrap.php | 6 ---- cake/libs/cake_log.php | 43 ++++++++++++++++++++++-- cake/libs/configure.php | 5 +++ cake/libs/controller/components/auth.php | 1 + cake/libs/debugger.php | 31 +++++++++++++++-- cake/libs/object.php | 14 +++----- cake/libs/view/templates/pages/home.ctp | 1 + 7 files changed, 82 insertions(+), 19 deletions(-) diff --git a/cake/bootstrap.php b/cake/bootstrap.php index 72530257c..5a366416c 100644 --- a/cake/bootstrap.php +++ b/cake/bootstrap.php @@ -47,12 +47,6 @@ if (!defined('PHP5')) { Configure::store(null, 'class.paths'); Configure::load('class.paths'); Configure::write('debug', DEBUG); -/** - * Verify that the application's salt has been changed from the default value - */ - if (CAKE_SESSION_STRING == 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi') { - trigger_error('Please change the value of CAKE_SESSION_STRING in app/config/core.php to a salt value specific to your application', E_USER_NOTICE); - } /** * Get the application path and request URL */ diff --git a/cake/libs/cake_log.php b/cake/libs/cake_log.php index 33227007c..785866187 100644 --- a/cake/libs/cake_log.php +++ b/cake/libs/cake_log.php @@ -33,13 +33,33 @@ if (!class_exists('File')) { uses('file'); } +/** + * Set up error level constants to be used within the framework if they are not defined within the + * system. + * + */ + if (!defined('LOG_WARNING')) { + define('LOG_WARNING', 3); + } + if (!defined('LOG_ERR')) { + define('LOG_ERR', LOG_ERROR); + } + if (!defined('LOG_NOTICE')) { + define('LOG_NOTICE', 4); + } + if (!defined('LOG_DEBUG')) { + define('LOG_DEBUG', 5); + } + if (!defined('LOG_INFO')) { + define('LOG_INFO', 6); + } /** * Logs messages to text files * * @package cake * @subpackage cake.cake.libs */ -class CakeLog{ +class CakeLog { /** * Writes given message to a log file in the logs directory. * @@ -48,7 +68,26 @@ class CakeLog{ * @return boolean Success */ function write($type, $msg) { - $filename = LOGS . $type . '.log'; + $levels = array( + LOG_WARNING => 'warning', + LOG_NOTICE => 'notice', + LOG_INFO => 'info', + LOG_DEBUG => 'debug', + LOG_ERR => 'error', + LOG_ERROR => 'error' + ); + + if (is_int($type) && isset($levels[$type])) { + $type = $levels[$type]; + } + + if ($type == 'error' || $type == 'warning') { + $filename = LOGS . 'error.log'; + } elseif (in_array($type, $levels)) { + $filename = LOGS . 'debug.log'; + } else { + $filename = LOGS . $type . '.log'; + } $output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $msg . "\n"; $log = new File($filename); return $log->append($output); diff --git a/cake/libs/configure.php b/cake/libs/configure.php index 347708850..ffd8703bd 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -146,8 +146,13 @@ class Configure extends Object { if(!class_exists('Debugger')) { require LIBS . 'debugger.php'; } + if (!class_exists('CakeLog')) { + uses('cake_log'); + } + Configure::write('log', LOG_NOTICE); } else { error_reporting(0); + Configure::write('log', LOG_NOTICE); } } } diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index e6a9678d2..6e1c41672 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -232,6 +232,7 @@ class AuthComponent extends Object { CAKE_ADMIN . '_delete' => 'delete' )); } + Debugger::checkSessionKey(); } /** * Main execution method. Handles redirecting of invalid users, and processing diff --git a/cake/libs/debugger.php b/cake/libs/debugger.php index 3f20a5bd6..ded0a5542 100644 --- a/cake/libs/debugger.php +++ b/cake/libs/debugger.php @@ -33,6 +33,7 @@ if (!class_exists('Object')) { uses('object'); } + uses('cake_log'); /** * Provide custom logging and error handling. * @@ -118,21 +119,25 @@ class Debugger extends Object { return; } + $level = LOG_DEBUG; switch ($code) { case E_PARSE: case E_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: $error = 'Fatal Error'; + $level = LOG_ERROR; break; case E_WARNING: case E_USER_WARNING: case E_COMPILE_WARNING: case E_RECOVERABLE_ERROR: $error = 'Warning'; + $level = LOG_WARNING; break; case E_NOTICE: $error = 'Notice'; + $level = LOG_NOTICE; break; default: return false; @@ -178,6 +183,10 @@ class Debugger extends Object { pr($this->trace(array('start' => 1))); e(''); + + if (Configure::read('log')) { + CakeLog::write($level, "{$error} ({$code}): {$description} in [{$file}, line {$line}]"); + } if ($error == 'Fatal Error') { die(); @@ -344,11 +353,29 @@ class Debugger extends Object { break; } } +/** + * Verify that the application's salt has been changed from the default value + * + */ + function checkSessionKey() { + if (CAKE_SESSION_STRING == 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi') { + trigger_error('Please change the value of CAKE_SESSION_STRING in app/config/core.php to a salt value specific to your application', E_USER_NOTICE); + } + } +/** + * Invokes the given debugger object as the current error handler, taking over control from the previous handler + * in a stack-like hierarchy. + * + * @param object $debugger A reference to the Debugger object + * @return void + */ + function invoke(&$debugger) { + set_error_handler(array(&$debugger, 'handleError')); + } } if (!defined('DISABLE_DEFAULT_ERROR_HANDLING')) { - $debugger =& Debugger::getInstance(); - set_error_handler(array(&$debugger, 'handleError')); + Debugger::invoke(Debugger::getInstance()); } ?> \ No newline at end of file diff --git a/cake/libs/object.php b/cake/libs/object.php index 3ad02b76c..3f8d2571d 100644 --- a/cake/libs/object.php +++ b/cake/libs/object.php @@ -36,7 +36,7 @@ * @package cake * @subpackage cake.cake.libs */ -class Object{ +class Object { /** * Log object * @@ -123,18 +123,14 @@ class Object{ if (!is_string($msg)) { ob_start(); print_r ($msg); - $msg=ob_get_contents(); + $msg = ob_get_contents(); ob_end_clean(); } - switch($type) { - case LOG_DEBUG: - return $this->_log->write('debug', $msg); - break; - default: - return $this->_log->write('error', $msg); - break; + if (!isset($this->_log->levels[$type])) { + $type = LOG_ERROR; } + return $this->_log->write($type, $msg); } /** * Allows setting of multiple properties of the object in a single line of code. diff --git a/cake/libs/view/templates/pages/home.ctp b/cake/libs/view/templates/pages/home.ctp index fe7aa24be..33b6b0c91 100644 --- a/cake/libs/view/templates/pages/home.ctp +++ b/cake/libs/view/templates/pages/home.ctp @@ -24,6 +24,7 @@ * @license http://www.opensource.org/licenses/mit-license.php The MIT License */ ?> +