From ca0b2d8b5f650aad37b2d53577379efb4b468044 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Mon, 29 Apr 2019 23:17:58 +0200 Subject: Improved email error logging --- includes/helper/email_helper.php | 16 ++++++++++++---- includes/sys_log.php | 9 +++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'includes') diff --git a/includes/helper/email_helper.php b/includes/helper/email_helper.php index 802debaa..bad0d539 100644 --- a/includes/helper/email_helper.php +++ b/includes/helper/email_helper.php @@ -2,6 +2,7 @@ use Engelsystem\Mail\EngelsystemMailer; use Engelsystem\Models\User\User; +use Psr\Log\LogLevel; /** * @param User $recipientUser @@ -13,17 +14,17 @@ use Engelsystem\Models\User\User; function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe = false) { if ($notIfItsMe && auth()->user()->id == $recipientUser->id) { - #return true; + return true; } /** @var \Engelsystem\Helpers\Translator $translator */ $translator = app()->get('translator'); $locale = $translator->getLocale(); - + try { /** @var EngelsystemMailer $mailer */ $mailer = app('mailer'); - + $translator->setLocale($recipientUser->settings->language); $status = $mailer->sendView( $recipientUser->contact->email ? $recipientUser->contact->email : $recipientUser->email, @@ -31,8 +32,15 @@ function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe 'emails/mail', ['username' => $recipientUser->name, 'message' => $message] ); - } catch(Exception $e) { + } catch (Exception $e) { $status = 0; + engelsystem_log(sprintf( + 'An exception occurred while sending a mail to %s in %s:%u: %s', + $recipientUser->name, + $e->getFile(), + $e->getLine(), + $e->getMessage() + ), LogLevel::CRITICAL); } $translator->setLocale($locale); diff --git a/includes/sys_log.php b/includes/sys_log.php index 595e8b55..9ac17dc0 100644 --- a/includes/sys_log.php +++ b/includes/sys_log.php @@ -1,14 +1,19 @@ user(); @@ -16,5 +21,5 @@ function engelsystem_log($message) $nick = User_Nick_render($user); } - $logger->info('{nick}: {message}', ['nick' => $nick, 'message' => $message]); + $logger->log($level, '{nick}: {message}', ['nick' => $nick, 'message' => $message]); } -- cgit v1.2.3-70-g09d2