Skip to content
This repository was archived by the owner on Mar 3, 2022. It is now read-only.

Commit

Permalink
Adding file path and line number to thrown exception in order to make…
Browse files Browse the repository at this point in the history
… debugging easier
  • Loading branch information
Ian Rose authored and brianreese committed Mar 21, 2016
1 parent d86d777 commit 65d9018
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions logger.module
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,26 @@ function logger_event($name, $type = 'count', $value = 1) {
// Assert valid event type.
$valid_types = array('count', 'gauge', 'set', 'time');
if (!in_array($type, $valid_types)) {
throw new InvalidArgumentException(sprintf('Invalid event type: "%s".', $type));
$backtrace = debug_backtrace();
if (isset($backtrace['1']['file']) && isset($backtrace['1']['line'])) {
$message = sprintf('Invalid event type: "%s" in %s on line %s.', $type, $backtrace['1']['file'], $backtrace['1']['line']);
}
else {
$message = sprintf('Invalid event type: "%s".', $type);
}
throw new InvalidArgumentException($message);
}

// Assert valid event value.
if (!is_int($value)) {
throw new InvalidArgumentException(sprintf('Invalid event value: "%s".', $value));
$backtrace = debug_backtrace();
if (isset($backtrace['1']['file']) && isset($backtrace['1']['line'])) {
$message = sprintf('Invalid event value: "%s" in %s on line %s.', $value, $backtrace['1']['file'], $backtrace['1']['line']);
}
else {
$message = sprintf('Invalid event value: "%s".', $value);
}
throw new InvalidArgumentException($message);
}

// Conditionally log events to watchdog for debugging purposes.
Expand Down

0 comments on commit 65d9018

Please sign in to comment.