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
This commit is contained in:
nate 2007-04-12 00:34:16 +00:00
parent 83daab2b28
commit b0307904ae
7 changed files with 82 additions and 19 deletions

View file

@ -47,12 +47,6 @@ if (!defined('PHP5')) {
Configure::store(null, 'class.paths'); Configure::store(null, 'class.paths');
Configure::load('class.paths'); Configure::load('class.paths');
Configure::write('debug', DEBUG); 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 * Get the application path and request URL
*/ */

View file

@ -33,13 +33,33 @@
if (!class_exists('File')) { if (!class_exists('File')) {
uses('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 * Logs messages to text files
* *
* @package cake * @package cake
* @subpackage cake.cake.libs * @subpackage cake.cake.libs
*/ */
class CakeLog{ class CakeLog {
/** /**
* Writes given message to a log file in the logs directory. * Writes given message to a log file in the logs directory.
* *
@ -48,7 +68,26 @@ class CakeLog{
* @return boolean Success * @return boolean Success
*/ */
function write($type, $msg) { 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"; $output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $msg . "\n";
$log = new File($filename); $log = new File($filename);
return $log->append($output); return $log->append($output);

View file

@ -146,8 +146,13 @@ class Configure extends Object {
if(!class_exists('Debugger')) { if(!class_exists('Debugger')) {
require LIBS . 'debugger.php'; require LIBS . 'debugger.php';
} }
if (!class_exists('CakeLog')) {
uses('cake_log');
}
Configure::write('log', LOG_NOTICE);
} else { } else {
error_reporting(0); error_reporting(0);
Configure::write('log', LOG_NOTICE);
} }
} }
} }

View file

@ -232,6 +232,7 @@ class AuthComponent extends Object {
CAKE_ADMIN . '_delete' => 'delete' CAKE_ADMIN . '_delete' => 'delete'
)); ));
} }
Debugger::checkSessionKey();
} }
/** /**
* Main execution method. Handles redirecting of invalid users, and processing * Main execution method. Handles redirecting of invalid users, and processing

View file

@ -33,6 +33,7 @@
if (!class_exists('Object')) { if (!class_exists('Object')) {
uses('object'); uses('object');
} }
uses('cake_log');
/** /**
* Provide custom logging and error handling. * Provide custom logging and error handling.
* *
@ -118,21 +119,25 @@ class Debugger extends Object {
return; return;
} }
$level = LOG_DEBUG;
switch ($code) { switch ($code) {
case E_PARSE: case E_PARSE:
case E_ERROR: case E_ERROR:
case E_CORE_ERROR: case E_CORE_ERROR:
case E_COMPILE_ERROR: case E_COMPILE_ERROR:
$error = 'Fatal Error'; $error = 'Fatal Error';
$level = LOG_ERROR;
break; break;
case E_WARNING: case E_WARNING:
case E_USER_WARNING: case E_USER_WARNING:
case E_COMPILE_WARNING: case E_COMPILE_WARNING:
case E_RECOVERABLE_ERROR: case E_RECOVERABLE_ERROR:
$error = 'Warning'; $error = 'Warning';
$level = LOG_WARNING;
break; break;
case E_NOTICE: case E_NOTICE:
$error = 'Notice'; $error = 'Notice';
$level = LOG_NOTICE;
break; break;
default: default:
return false; return false;
@ -179,6 +184,10 @@ class Debugger extends Object {
pr($this->trace(array('start' => 1))); pr($this->trace(array('start' => 1)));
e('</div>'); e('</div>');
if (Configure::read('log')) {
CakeLog::write($level, "{$error} ({$code}): {$description} in [{$file}, line {$line}]");
}
if ($error == 'Fatal Error') { if ($error == 'Fatal Error') {
die(); die();
} }
@ -344,11 +353,29 @@ class Debugger extends Object {
break; 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')) { if (!defined('DISABLE_DEFAULT_ERROR_HANDLING')) {
$debugger =& Debugger::getInstance(); Debugger::invoke(Debugger::getInstance());
set_error_handler(array(&$debugger, 'handleError'));
} }
?> ?>

View file

@ -36,7 +36,7 @@
* @package cake * @package cake
* @subpackage cake.cake.libs * @subpackage cake.cake.libs
*/ */
class Object{ class Object {
/** /**
* Log object * Log object
* *
@ -123,18 +123,14 @@ class Object{
if (!is_string($msg)) { if (!is_string($msg)) {
ob_start(); ob_start();
print_r ($msg); print_r ($msg);
$msg=ob_get_contents(); $msg = ob_get_contents();
ob_end_clean(); ob_end_clean();
} }
switch($type) { if (!isset($this->_log->levels[$type])) {
case LOG_DEBUG: $type = LOG_ERROR;
return $this->_log->write('debug', $msg);
break;
default:
return $this->_log->write('error', $msg);
break;
} }
return $this->_log->write($type, $msg);
} }
/** /**
* Allows setting of multiple properties of the object in a single line of code. * Allows setting of multiple properties of the object in a single line of code.

View file

@ -24,6 +24,7 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
?> ?>
<?php Debugger::checkSessionKey(); ?>
<p> <p>
<span class="notice"> <span class="notice">
<?php <?php