Skip to content

Commit

Permalink
Merge pull request #1596 from tripal/tv4g0-issue1581-tripal-logger-de…
Browse files Browse the repository at this point in the history
…bug-level

Always print debug messages
  • Loading branch information
laceysanderson committed Aug 10, 2023
2 parents a9d3aba + febfb15 commit 70317f6
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions tripal/src/Services/TripalLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,9 @@ public function critical($message, $context = [], $options=[]) {
* - Server log
* - Drupal Message (if specified in options)
*
* This function behaves differently from the Drupal::logger->debug function
* because no debugging information will be logged unless the TRIPAL_DEBUG
* environment variable is set. This if for backwards compatibility with
* Tripal v3.
* For Tripal 3, no debug messages were logged unless the TRIPAL_DEBUG
* environment variable is set. Under Tripal 4, debug messages are
* always printed.
*
* @param $message
* The message MUST be a string or object implementing __toString().
Expand All @@ -545,26 +544,27 @@ public function critical($message, $context = [], $options=[]) {
public function debug($message, $context = [], $options=[]) {
if ($this->isSuppressed()) return;

// If we are not set to return debugging information and the severity level
// is debug then don't report the error.
// Get the backtrace and include in the error message, but only if the
// TRIPAL_DEBUG environment variable is set.
// (In Tripal 3 this was added to all levels)
if (getenv('TRIPAL_DEBUG') == 1) {
// If we want to implement a toggle for debug messages in the
// future, it could go here. Tripal 3 had an environment variable
// TRIPAL_DEBUG to perform this function.
if (true) {
$backtrace = debug_backtrace();
$message .= "\nBacktrace:\n";
$i = 1;
for ($i = 1; $i < count($backtrace); $i++) {
$function = $backtrace[$i];
$message .= " $i) " . $function['function'] . "\n";
}

$this->log2job('DEBUG: ' . $message, $context);
if (!array_key_exists('logger', $options) or $options['logger'] !== FALSE) {
$message_str = $this->messageString($message, $context);
$this->logger->debug($message_str);
}

if (isset($options['drupal_set_message'])) {
$this->log2Message('debug', $message, $context);
}

$this->log2Server('DEBUG: ' . $message, $context, $options);
}
}
Expand Down

0 comments on commit 70317f6

Please sign in to comment.