okaufmann/laravel-notification-log
Composer 安装命令:
composer require okaufmann/laravel-notification-log
包简介
Logs every sent Notification and Mail of your entire Project.
README 文档
README
Logs every sent Notification of your entire Laravel Project.
Installation
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), ];
Usage
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.
Custom Message Resolution
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.
Resolving Messages After Sending
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:
- Templates are stored externally (like WhatsApp Business API)
- The actual message content is only available after sending
- You need to extract information from the channel's response data
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.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.
okaufmann/laravel-notification-log 适用场景与选型建议
okaufmann/laravel-notification-log 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24.06k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2024 年 07 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「laravel-notification-log」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 okaufmann/laravel-notification-log 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 okaufmann/laravel-notification-log 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 okaufmann/laravel-notification-log 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Log notifications sent by your Laravel app
Logs every sent Notification and Mail of your entire Project.
Alfabank REST API integration
Logs every sent Notification and Mail of your entire Project.
Laravel package for Accurate Online API integration.
Shared RCX Laravel DataTables UI and configuration helpers.
统计信息
- 总下载量: 24.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-05