Discovered that an earlier implementation of Model::pr is now being overridden by the AppModel. This is probably a good thing, but it does mean that we're getting a ton of Model prints that we don't want. I added a class logging mechanism to allow individual classes to be turned up or down, and set the default for Model to be very low

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@438 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-31 00:00:10 +00:00
parent 9360ebe661
commit 87db010dc1

View File

@@ -45,6 +45,9 @@ class AppModel extends Model {
// Default Log Level, if not specified at the function level
var $default_log_level = 1;
// Class specific log levels
var $class_log_level = array('Model' => 5);
// Function specific log levels
var $function_log_level = array();
@@ -55,6 +58,17 @@ class AppModel extends Model {
var $max_log_level;
// REVISIT <AP>: 20090730
// Why is this constructor crashing?
// Clearly it's in some sort of infinite
// loop, but it seems the correct way
// to have a constructor call the parent...
/* function __construct() { */
/* parent::__construct(); */
/* $this->prClassLevel(5, 'Model'); */
/* } */
/**************************************************************************
**************************************************************************
**************************************************************************
@@ -62,12 +76,24 @@ class AppModel extends Model {
* - Prints out debug information, if the log level allows
*/
function prFunctionLevel($level) {
function prClassLevel($level, $class = null) {
$trace = debug_backtrace(false);
$caller = array_shift($trace);
$caller = array_shift($trace);
$function = $caller['function'];
$this->function_log_level[$function] = $level;
if (empty($class))
$class = $caller['class'];
$this->class_log_level[$class] = $level;
}
function prFunctionLevel($level, $function = null, $class = null) {
$trace = debug_backtrace(false);
$caller = array_shift($trace);
$caller = array_shift($trace);
if (empty($class))
$class = $caller['class'];
if (empty($function))
$function = $caller['function'];
$this->function_log_level["{$class}-{$function}"] = $level;
}
function _pr($level, $mixed, $checkpoint = null) {
@@ -94,8 +120,10 @@ class AppModel extends Model {
//$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->class_log_level[$class]))
$log_level = $this->class_log_level[$class];
if (isset($this->function_log_level["{$class}-{$function}"]))
$log_level = $this->function_log_level["{$class}-{$function}"];
if (isset($this->min_log_level))
$log_level = max($log_level, $this->min_log_level);
if (isset($this->max_log_level))
@@ -116,6 +144,7 @@ class AppModel extends Model {
echo '<DIV CLASS="pr-caller">';
echo '<strong>' . substr(str_replace(ROOT, '', $file), 1) . '</strong>';
echo ' (line <strong>' . $line . '</strong>)';
echo ' : level-' . $level;
echo '</DIV>' . "\n";
pr(array("{$class}::{$function}()" => $mixed), false, false);