0 && $this->getParam('display_errors')) {
echo "\n';
}
switch ($message['type']) {
case MSG_ERR:
echo '
' . $message['message'] . '
';
break;
case MSG_WARNING:
echo '
' . $message['message'] . '
';
break;
case MSG_SUCCESS:
echo '
' . $message['message'] . '
';
break;
case MSG_NOTICE:
default:
echo '
' . $message['message'] . '
';
break;
}
?>
logPriorityToString($priority)) {
$this->logMsg(sprintf('Log priority %s not defined. (Message: %s)', $priority, $message), LOG_EMERG, $file, $line);
$priority = LOG_EMERG;
}
// If log file is not specified, don't log to a file.
if (!$this->getParam('log_directory') || !$this->getParam('log_filename') || !is_dir($this->getParam('log_directory')) || !is_writable($this->getParam('log_directory'))) {
$this->setParam(array('log_file_priority' => false));
// We must use trigger_error to report this problem rather than calling App::logMsg, which might lead to an infinite loop.
trigger_error(sprintf('Codebase error: log directory (%s) not found or writable.', $this->getParam('log_directory')), E_USER_NOTICE);
}
// Make sure to log in the system's locale.
$locale = setlocale(LC_TIME, 0);
setlocale(LC_TIME, 'C');
// Data to be stored for a log event.
$event = array();
$event['date'] = date('Y-m-d H:i:s');
$event['remote ip'] = getRemoteAddr();
if (substr(PHP_OS, 0, 3) != 'WIN') {
$event['pid'] = posix_getpid();
}
$event['type'] = $this->logPriorityToString($priority);
$event['file:line'] = "$file : $line";
preg_match_all('/(<[^>\s]{7,})[^>]*>/', $message, $strip_tags_allow); // <...> with lots of chars maybe we don't want stripped.
$event['message'] = strip_tags(preg_replace('/\s+/', ' ', $message), (!empty($strip_tags_allow[1]) ? join('> ', $strip_tags_allow[1]) . '>' : null));
$event_str = '[' . join('] [', $event) . ']';
// FILE ACTION
if ($this->getParam('log_file_priority') && $priority <= $this->getParam('log_file_priority')) {
error_log($event_str . "\n", 3, $this->getParam('log_directory') . '/' . $this->getParam('log_filename'));
}
// EMAIL ACTION
if ($this->getParam('log_email_priority') && $priority <= $this->getParam('log_email_priority')) {
$subject = sprintf('[%s %s] %s', getenv('HTTP_HOST'), $event['type'], $message);
$email_msg = sprintf("A %s log event occured on %s\n\n", $event['type'], getenv('HTTP_HOST'));
$headers = "From: codebase@strangecode.com";
foreach ($event as $k=>$v) {
$email_msg .= sprintf("%-11s%s\n", $k, $v);
}
mail($this->getParam('log_to_email_address'), $subject, $email_msg, $headers, '-f codebase@strangecode.com');
}
// SMS ACTION
if ($this->getParam('log_sms_priority') && $priority <= $this->getParam('log_sms_priority')) {
$subject = sprintf('[%s %s]', getenv('HTTP_HOST'), $priority);
$sms_msg = sprintf('%s [%s:%s]', $event['message'], basename($file), $line);
$headers = "From: codebase@strangecode.com";
mail($this->getParam('log_to_sms_address'), $subject, $sms_msg, $headers, '-f codebase@strangecode.com');
}
// SCREEN ACTION
if ($this->getParam('log_screen_priority') && $priority <= $this->getParam('log_screen_priority')) {
echo "[{$event['date']}] [{$event['type']}] [{$event['file:line']}] [{$event['message']}]\n";
}
// Restore original locale.
setlocale(LC_TIME, $locale);
}
/**
* Returns the string representation of a LOG_* integer constant.
*
* @param int $priority The LOG_* integer constant.
*
* @return The string representation of $priority.
*/
function logPriorityToString ($priority) {
$priorities = array(
LOG_EMERG => 'emergency',
LOG_ALERT => 'alert',
LOG_CRIT => 'critical',
LOG_ERR => 'error',
LOG_WARNING => 'warning',
LOG_NOTICE => 'notice',
LOG_INFO => 'info',
LOG_DEBUG => 'debug'
);
if (isset($priorities[$priority])) {
return $priorities[$priority];
} else {
return false;
}
}
/**
* Sets which query arguments will be carried persistently between requests.
* Values in the _carry_queries array will be copied to URLs (via App::url()) and
* to hidden input values (via printHiddenSession()).
*
* @access public
* @param string $query_key The key of the query argument to save.
* @author Quinn Comendant