getMessage(). "\n."; $options['print'] = TRUE; } // Format the message for printing (either to the screen, log or both) if (sizeof($variables) > 0) { $print_message = str_replace(array_keys($variables), $variables, $message); } else { $print_message = $message; } // If print option supplied then print directly to the screen if (isset($options['print'])) { print $severity_string . ' (' . strtoupper($type) . '): ' . $print_message . "\n"; } // Print to the Tripal error log tripal_log( $severity_string . ' (' . strtoupper($type) . '): ' . $print_message . "\n", 'error'); } /** * Display messages to tripal administrators. This can be used instead of * drupal_set_message when you want to target tripal administrators. * * @param $message * The message to be displayed to the tripal administrators * @param $importance * The level of importance for this message. In the future this will be used to allow * administrators to filter some of these messages. It can be one of the following: * - TRIPAL_CRITICAL: Critical conditions. * - TRIPAL_ERROR: Error conditions. * - TRIPAL_WARNING: Warning conditions. * - TRIPAL_NOTICE: Normal but significant conditions. * - TRIPAL_INFO: (default) Informational messages. * - TRIPAL_DEBUG: Debug-level messages. * @param $options * Any options to apply to the current message. Supported options include: * - return_html: return HTML instead of setting a drupal message. This can be * used to place a tripal message in a particular place in the page. * The default is FALSE. */ function tripal_set_message($message, $importance = TRIPAL_INFO, $options = array()) { global $user; // Only show the message to the users with 'view dev helps' permission. if (!user_access('view dev helps')) { return ''; } // set defaults $options['return_html'] = (isset($options['return_html'])) ? $options['return_html'] : FALSE; // Get human-readable severity string $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; } // Mark-up the Message $full_message = '
'; // Handle whether to return the HTML & let the caller deal with it // or to use drupal_set_message to put it near the top of the page & let the theme deal with it if ($options['return_html']) { return ' '; } else { drupal_set_message($full_message, 'tripal-site-admin-only'); } } /** * File-based Logging for Tripal * * @param $message * The message to be logged. Need not contain date/time information * @param $log_type * The type of log. Should be one of 'error' or 'job' although other types * are supported. * @param $options * An array of options where the following keys are supported: * - first_progress_bar: this sohuld be used for the first log call for a progress bar * - is_progress_bar: this option should be used for all but the first print of a * progress bar to allow it all to be printed on the same line without intervening * date prefixes * @return * The number of bytes that were written to the file, or FALSE on failure */ function tripal_log($message, $type = 'error', $options = array()) { global $base_url; $prefix = '[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 = trim($message); } return error_log($message); }