Logs every sent Notification and Mail of your entire Project.
okaufmann/laravel-notification-log is a Laravel package for logs every sent notification and mail of your entire project..
It currently has 4 GitHub stars and 26.163 downloads on Packagist (latest version v6.1.0).
Install it with composer require okaufmann/laravel-notification-log.
Discover more Laravel packages by okaufmann
or browse all Laravel packages to compare alternatives.
Last updated
Logs every sent Notification of your entire Laravel Project.
You can install the package via composer:
composer require okaufmann/laravel-notification-log
You can publish and run the migrations with:
php artisan vendor:publish --tag="notification-log-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="notification-log-config"
The following config file will be published in config/notification-log.php:
return [
/*
|--------------------------------------------------------------------------
| Resolve Notification Message
|--------------------------------------------------------------------------
|
| If this is enabled, the Logger will try to resolve the built message
| out of the notification. This is useful if you want to debug your
| sent notifications.
|
*/
'resolve_notification_message' => env('NOTIFICATION_LOG_RESOLVE_NOTIFICATION_MESSAGE', false),
];
Add the following Interface and Trait to your Notification:
use Okaufmann\LaravelNotificationLog\Contracts\ShouldLogNotification;use Okaufmann\LaravelNotificationLog\Models\Concerns\LogsNotifications;
class DummyNotification extends Notification implements ShouldLogNotification
{
use LogsNotifications;
// ...
}
Now send a Notification or Mail as you would normally do. The package will automatically log the Notification or Mail.
If you want to customize how the notification message is resolved for logging purposes, you can implement the ResolveMessageForLogging interface:
use Okaufmann\LaravelNotificationLog\Contracts\ShouldLogNotification;
use Okaufmann\LaravelNotificationLog\Contracts\ResolveMessageForLogging;
use Okaufmann\LaravelNotificationLog\Models\Concerns\LogsNotifications;
class CustomNotification extends Notification implements ShouldLogNotification, ResolveMessageForLogging
{
use LogsNotifications;
public function resolveMessageForLogging(string $channel, $notifiable): string
{
$channelName = get_class($channel);
$notifiableName = get_class($notifiable);
return "Custom message for {$channelName} channel sent to {$notifiableName}";
}
}
When a notification implements ResolveMessageForLogging, the logger will use your custom method instead of the default message resolution logic. This gives you full control over what gets stored in the message field of the notification log.
For special channels like WhatsApp, Telegram, or other messaging services where templates are stored externally and the actual message content is only available after sending, you can implement the ResolveMessageForLoggingAfterSent interface:
use Okaufmann\LaravelNotificationLog\Contracts\ShouldLogNotification;
use Okaufmann\LaravelNotificationLog\Contracts\ResolveMessageForLoggingAfterSent;
use Okaufmann\LaravelNotificationLog\Models\Concerns\LogsNotifications;
class WhatsAppNotification extends Notification implements ShouldLogNotification, ResolveMessageForLoggingAfterSent
{
use LogsNotifications;
public function resolveMessageForLoggingAfterSent(mixed $channel, $notifiable, $response): ?string
{
// Extract the actual message content from the WhatsApp API response
if (isset($response['message_id'])) {
return "WhatsApp message sent with ID: {$response['message_id']}";
}
return null;
}
}
This interface is particularly useful for channels where:
The method is called during the NotificationSent event, allowing you to resolve the message content using the response data from the channel after the notification has been successfully sent.
composer test
Please see CHANGELOG for more information on what has changed recently.
The MIT License (MIT). Please see License File for more information.