public function InstapageCmsPluginDebugLogModel::write in Instapage plugin 8.3
Same name and namespace in other branches
- 7.3 core/models/InstapageCmsPluginDebugLogModel.php \InstapageCmsPluginDebugLogModel::write()
Wtites an entry in the debug log.
Parameters
string $value Message to be written in the log.:
string $name Additional name for the written value. Default: ''.:
bool $addCaller Do you want to include the stack trace to an antry? Default: true.:
File
- core/
models/ InstapageCmsPluginDebugLogModel.php, line 42
Class
- InstapageCmsPluginDebugLogModel
- Class responsible for storing the data in debug log.
Code
public function write($value, $name = '', $addCaller = true) {
try {
if (is_array($value) || is_object($value)) {
$value = print_r($value, true);
}
$caller = '';
if ($addCaller) {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$traceLength = 3;
$callerArr = array();
for ($i = 1; $i <= $traceLength; ++$i) {
$caller = isset($trace[$i]) ? $trace[$i] : null;
$callerFunction = isset($caller['function']) ? $caller['function'] : null;
if ($callerFunction == 'writeLog' || $callerFunction == 'writeDiagnostics') {
$traceLength = 4;
continue;
}
$callerClass = isset($caller['class']) ? $caller['class'] . ' :: ' : null;
if ($caller === null) {
break;
}
$callerArr[] = $callerClass . $callerFunction;
}
}
$caller = implode("\r\n", $callerArr);
$db = InstapageCmsPluginDBModel::getInstance();
$sql = 'INSERT INTO ' . $db->debugTable . ' VALUES(NULL, %s, %s, %s, %s)';
$db
->query($sql, date('Y-m-d H:i:s'), $value, $caller, $name);
} catch (Exception $e) {
echo $e
->getMessage();
}
}