public function TripalJob::logMessage

3.x TripalJob.inc public TripalJob::logMessage($message, $variables = array(), $severity = TRIPAL_INFO)

Logs a message for the job.

There is no distinction between status messages and error logs. Any message that is intended for the user to review the status of the job can be provided here.

Messages that are are of severity TRIPAL_CRITICAL or TRIPAL_ERROR are also logged to the watchdog.

Logging works regardless if the job uses a transaction. If the transaction must be rolled back to to an error the error messages will persist.

Parameters

$message: The message to store in the log. Keep $message translatable by not concatenating dynamic values into it! Variables in the message should be added by using placeholder strings alongside the variables argument to declare the value of the placeholders. See t() for documentation on how $message and $variables interact.

$variables: Array of variables to replace in the message on display or NULL if message is already translated or not possible to translate.

$severity: The severity of the message; one of the following values:

File

tripal/includes/TripalJob.inc, line 615

Class

TripalJob

Code

public function logMessage($message, $variables = array(), $severity = TRIPAL_INFO) {
  // Generate a translated message.
  $tmessage = t($message, $variables);

  // For the sake of the command-line user, print the message to the
  // terminal.
  print $tmessage . "\n";

  // Add this message to the job's log.
  $this->job->error_msg .= "\n" . $tmessage;

  // Report this message to watchdog or set a message.
  if ($severity == TRIPAL_CRITICAL or $severity == TRIPAL_ERROR) {
    tripal_report_error('tripal_job', $severity, $message, $variables);
    $this->job->status = 'Error';
  }
}