shaffe / laravel-mail-log-channel
A package to support logging via email in Laravel
Installs: 53 507
Dependents: 0
Suggesters: 0
Security: 0
Stars: 11
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- illuminate/bus: ^5.6|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/contracts: ^5.6|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/log: ^5.6|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/mail: ^5.6|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/queue: ^5.6|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^5.6|^6.0|^7.|^8.00|^9.0|^10.|^11.00
README
A service provider to add support for logging via email using Laravels built-in mail provider.
This package is a fork of laravel-log-mailer by Steve Porter.
Table of contents
Installation
You can install this package via composer using this commande:
composer require shaffe/laravel-mail-log-channel
Laravel version compatibility
The package will automatically register itself if you use Laravel.
For usage with Lumen, add the service provider in bootstrap/app.php
.
$app->register(Shaffe\MailLogChannel\MailLogChannelServiceProvider::class);
Configuration
To ensure all unhandled exceptions are mailed:
- create a
mail
logging channel inconfig/logging.php
, - add this
mail
channel to your current logging stack, - add a
LOG_MAIL_ADDRESS
to your.env
file to define the recipient.
You can specify multiple channels and individually change the recipients, the subject and the email template.
'channels' => [ 'stack' => [ 'driver' => 'stack', // 2. Add mail to the stack: 'channels' => ['single', 'mail'], ], // ... // 1. Create a mail logging channel: 'mail' => [ 'driver' => 'mail', 'level' => env('LOG_MAIL_LEVEL', 'notice'), // Specify mail recipient 'to' => [ [ 'address' => env('LOG_MAIL_ADDRESS'), 'name' => 'Error', ], ], 'from' => [ // Defaults to config('mail.from.address') 'address' => env('LOG_MAIL_ADDRESS'), // Defaults to config('mail.from.name') 'name' => 'Errors' ], // Optionally overwrite the subject format pattern // 'subject_format' => env('LOG_MAIL_SUBJECT_FORMAT', '[%datetime%] %level_name%: %message%'), // Optionally overwrite the mailable template // Two variables are sent to the view: `string $content` and `array $records` // 'mailable' => NewLogMailable::class ], ],
Recipients configuration format
The following to
config formats are supported:
-
single email address:
'to' => env('LOG_MAIL_ADDRESS', ''),
-
array of email addresses:
'to' => explode(',', env('LOG_MAIL_ADDRESS', '')),
-
associative array of email => name addresses:
'to' => [env('LOG_MAIL_ADDRESS', '') => 'Error'],`
-
array of email and name:
'to' => [ [ 'address' => env('LOG_MAIL_ADDRESS', ''), 'name' => 'Error', ], ],