123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- <?php
- define('TRIPAL_CRITICAL',2);
- define('TRIPAL_ERROR',3);
- define('TRIPAL_WARNING',4);
- define('TRIPAL_NOTICE',5);
- define('TRIPAL_INFO',6);
- define('TRIPAL_DEBUG',7);
- function tripal_report_error($type, $severity, $message, $variables = array(), $options = array()) {
-
- $severity_string = '';
- switch ($severity) {
- case TRIPAL_CRITICAL:
- $severity_string = 'CRITICAL';
- break;
- case TRIPAL_ERROR:
- $severity_string = 'ERROR';
- break;
- case TRIPAL_WARNING:
- $severity_string = 'WARNING';
- break;
- case TRIPAL_NOTICE:
- $severity_string = 'NOTICE';
- break;
- case TRIPAL_INFO:
- $severity_string = 'INFO';
- break;
- case TRIPAL_DEBUG:
- $severity_string = 'DEBUG';
- break;
- }
-
-
- if (getenv('TRIPAL_DEBUG') == 1) {
- $backtrace = debug_backtrace();
- $message .= "\nBacktrace:\n";
- $i = 1;
- for ($i = 1; $i < count($backtrace); $i++) {
- $function = $backtrace[$i];
- $message .= " $i) " . $function['function'] . "\n";
- }
- }
-
- try {
- watchdog($type, $message, $variables, $severity);
- }
- catch (Exception $e) {
- print "CRITICAL (TRIPAL_CORE): Unable to register error message with watchdog: " . $e->getMessage(). "\n.";
- $options['print'] = TRUE;
- }
-
- if (sizeof($variables) > 0) {
- $print_message = str_replace(array_keys($variables), $variables, $message);
- }
- else {
- $print_message = $message;
- }
-
- if (isset($options['print'])) {
- print $severity_string . ' (' . strtoupper($type) . '): ' . $print_message . "\n";
- }
-
- tripal_log('[' . strtoupper($type) . '] ' . $print_message . "\n", $severity_string);
- }
- function tripal_set_message($message, $importance = TRIPAL_INFO, $options = array()) {
- global $user;
-
- if (!user_access('view dev helps')) {
- return '';
- }
-
- $options['return_html'] = (isset($options['return_html'])) ? $options['return_html'] : FALSE;
-
- $importance_string = '';
- switch ($importance) {
- case TRIPAL_CRITICAL:
- $importance_string = 'CRITICAL';
- break;
- case TRIPAL_ERROR:
- $importance_string = 'ERROR';
- break;
- case TRIPAL_WARNING:
- $importance_string = 'WARNING';
- break;
- case TRIPAL_NOTICE:
- $importance_string = 'NOTICE';
- break;
- case TRIPAL_INFO:
- $importance_string = 'INFO';
- break;
- case TRIPAL_DEBUG:
- $importance_string = 'DEBUG';
- break;
- }
-
- $full_message =
- '<div class="tripal-site-admin-message">'
- . '<span class="tripal-severity-string ' . strtolower($importance_string) . '">' . $importance_string . ': </span>'
- . $message
- . '</div>';
-
-
- if ($options['return_html']) {
- return '<div class="messages tripal-site-admin-only">' . $full_message . '</div>';
- }
- else {
- drupal_set_message($full_message, 'tripal-site-admin-only');
- }
- }
- function tripal_log($message, $type = 'error', $options = array()) {
- global $base_url;
- $prefix = '[site ' . $base_url . '] [TRIPAL ' . strtoupper(check_plain($type)) . '] ';
- if (!isset($options['is_progress_bar'])) {
- $message = $prefix . str_replace("\n", "", trim($message));
- }
- if (isset($options['first_progress_bar'])) {
- $message = $prefix . trim($message);
- }
- return error_log($message);
- }
|