Skip to content

Commit

Permalink
Minor improvements to logging mwrun
Browse files Browse the repository at this point in the history
  • Loading branch information
colinmollenhour committed Mar 19, 2024
1 parent 6e46040 commit 087f868
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
10 changes: 8 additions & 2 deletions app/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function __construct($plugin, $debug = FALSE)
public function addEventQueue(array $event)
{
$this->_eventQueue[] = $event;
$this->log('Event added to queue: '.json_encode($event));
}

/**
Expand All @@ -79,7 +80,12 @@ public function runEventQueue()
{
foreach ($this->_eventQueue as $event) {
[$eventMethod, $param] = $event;
$this->_pluginInstance->$eventMethod($param);
try {
$this->_pluginInstance->$eventMethod($param);
$this->log('Event processed successfully: '.$eventMethod);
} catch (Throwable $e) {
$this->log('Error processing event '.$eventMethod.': '.$e->getMessage());
}
}
}

Expand Down Expand Up @@ -113,7 +119,7 @@ public function hasConnection()
*/
public function diagnostics()
{
return $this->_pluginInstance->connectionDiagnostics();
return $this->_pluginInstance->connectionDiagnostics(TRUE);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion pub/callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
if (empty($middleware)) {
error_log($e->getMessage());
} else {
$middleware->log("{$e->getCode()} {$e->getMessage()}");
$middleware->logException($e);
}
http_response_code($e->getCode() ?: 500);
}
10 changes: 4 additions & 6 deletions pub/oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@
echo $middleware->renderPage('oauth_status.phtml');

} catch (Exception $e) {
if ($debug) {
if (empty($middleware)) {
error_log($e->getMessage());
} else {
$middleware->log("{$e->getCode()} {$e->getMessage()}");
}
if (empty($middleware)) {
error_log($e->getMessage());
} else {
$middleware->logException($e);
}
echo $e->getMessage();
}
10 changes: 4 additions & 6 deletions pub/respond.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@
$middleware->log(sprintf('Received webhook for %s topic with message: %s', $topic, $json), 'webhooks.log');
$middleware->respond($topic, $message);
} catch (Exception $e) {
if ($debug) {
if (empty($middleware)) {
error_log($e->getMessage());
} else {
$middleware->log("{$e->getCode()} {$e->getMessage()}");
}
if (empty($middleware)) {
error_log($e->getMessage());
} else {
$middleware->logException($e);
}
http_response_code($e->getCode() ?: 500);
}
10 changes: 4 additions & 6 deletions pub/webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@

$middleware->webhookController($query, $headers, $data);
} catch (Exception $e) {
if ($debug) {
if (empty($middleware)) {
error_log($e->getMessage());
} else {
$middleware->log("{$e->getCode()} {$e->getMessage()}");
}
if (empty($middleware)) {
error_log($e->getMessage());
} else {
$middleware->logException($e);
}
http_response_code($e->getCode() ?: 500);
}
2 changes: 1 addition & 1 deletion run.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
$debug = TRUE;
array_pop($argv);
}
if ($argc == 2) {
if ($argc <= 2) {
die($usage);
}

Expand Down

0 comments on commit 087f868

Please sign in to comment.