Finally added a logging mechanism. Only one file has been converted at the moment. I'll go in pieces, as debugging goes on.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@436 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-30 23:20:47 +00:00
parent a1f30804a7
commit c0d26a8e95
2 changed files with 143 additions and 88 deletions

View File

@@ -42,6 +42,90 @@ class AppModel extends Model {
var $useNullForEmpty = true;
var $formatDateFields = true;
// Default Log Level, if not specified at the function level
var $default_log_level = 1;
// Function specific log levels
var $function_log_level = array();
// Force the module to log at LEAST at this level
var $min_log_level;
// Force logging of nothing higher than this level
var $max_log_level;
/**************************************************************************
**************************************************************************
**************************************************************************
* function: pr
* - Prints out debug information, if the log level allows
*/
function prFunctionLevel($level) {
$trace = debug_backtrace(false);
$caller = array_shift($trace);
$caller = array_shift($trace);
$function = $caller['function'];
$this->function_log_level[$function] = $level;
}
function _pr($level, $mixed, $checkpoint = null) {
$log_level = $this->default_log_level;
$trace = debug_backtrace(false);
// Get rid of pr/prEnter/prExit
$caller = array_shift($trace);
// The next entry shows where pr was called from, but it
// shows _what_ was called, which is pr/prEntry/prExit.
$caller = array_shift($trace);
$file = $caller['file'];
$line = $caller['line'];
// So, this caller holds the calling function name
$caller = array_shift($trace);
$function = $caller['function'];
$class = $caller['class'];
//$class = $this->name;
// Adjust the log level from default, if necessary
if (isset($this->function_log_level[$function]))
$log_level = $this->function_log_level[$function];
if (isset($this->min_log_level))
$log_level = max($log_level, $this->min_log_level);
if (isset($this->max_log_level))
$log_level = min($log_level, $this->max_log_level);
// If the level is insufficient, bail out
if ($level > $log_level)
return;
if (!empty($checkpoint)) {
$chk = array("checkpoint" => $checkpoint);
if (is_array($mixed))
$mixed = $chk + $mixed;
else
$mixed = $chk + array($mixed);
}
pr(array("{$class}::{$function} (line {$line})" => $mixed));
}
function pr($level, $mixed, $checkpoint = null) {
$this->_pr($level, $mixed, $checkpoint);
}
function prEnter($args, $level = 15) {
$this->_pr($level, $args, 'Function Entry');
}
function prExit($retval, $level = 16) {
$this->_pr($level, $retval, 'Function Exit');
return $retval;
}
/**************************************************************************
**************************************************************************