From 93dce7b76a906e84d2e7679f5868394dbfe433b8 Mon Sep 17 00:00:00 2001 From: John Beales Date: Mon, 16 Sep 2019 10:24:04 -0400 Subject: [PATCH 1/9] Update compser.json to allow Larvel 6 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e0cc2fb..4966298 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "designmynight" ], "require": { - "illuminate/support": "^5.6" + "illuminate/support": "^5.6|^6" }, "autoload": { "psr-4": { From 25cc79b82fcee6c82a2418e1a407a1aa80e9d64b Mon Sep 17 00:00:00 2001 From: John Beales Date: Mon, 16 Sep 2019 11:36:07 -0400 Subject: [PATCH 2/9] Laravel 6 compatibility. --- README.md | 1 + src/Logging/Driver/MailableLogger.php | 5 ++++- src/Logging/Monolog/Handlers/MailableHandler.php | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7b14a7c..aff6905 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ composer require designmynight/laravel-log-mailer Laravel | Package | :---------|:--------| + 6.x | 1.0.x | 5.6.x | 1.0.x | And add the service provider in `config/app.php`: diff --git a/src/Logging/Driver/MailableLogger.php b/src/Logging/Driver/MailableLogger.php index a31008e..c69ae2e 100644 --- a/src/Logging/Driver/MailableLogger.php +++ b/src/Logging/Driver/MailableLogger.php @@ -20,7 +20,10 @@ class MailableLogger */ public function __invoke(array $config) { - $this->config = $config; + $this->config = array_merge([ + 'level' => Logger::DEBUG, + 'bubble' => true + ], $config ); $mailHandler = new MailableHandler( $this->buildMailable(), diff --git a/src/Logging/Monolog/Handlers/MailableHandler.php b/src/Logging/Monolog/Handlers/MailableHandler.php index d6c1de1..c239b96 100644 --- a/src/Logging/Monolog/Handlers/MailableHandler.php +++ b/src/Logging/Monolog/Handlers/MailableHandler.php @@ -19,7 +19,7 @@ class MailableHandler extends MailHandler * * @return void */ - public function __construct(Mailable $mailable, LineFormatter $subjectFormatter, $level = Logger::DEBUG, $bubble = true) + public function __construct(Mailable $mailable, LineFormatter $subjectFormatter, int $level = Logger::DEBUG, bool $bubble = true) { parent::__construct($level, $bubble); $this->mailer = app()->make('mailer'); @@ -42,7 +42,7 @@ protected function setSubject(array $records) /** * {@inheritdoc} */ - protected function send($content, array $records) + protected function send(string $content, array $records): void { $this->mailable->with([ 'content' => $content, From 52681a1110fcb02deabec27267e8df4649a82ec0 Mon Sep 17 00:00:00 2001 From: John Beales Date: Fri, 4 Oct 2019 22:54:01 -0400 Subject: [PATCH 3/9] Let's not load views in the register() method. Especially from a place that may not be available, and when we're about to load them again in the boot() method. (Fixes a fatal error running artisan view:cache) --- src/Logging/MailableLogServiceProvider.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Logging/MailableLogServiceProvider.php b/src/Logging/MailableLogServiceProvider.php index d4a1a7b..64d93b7 100644 --- a/src/Logging/MailableLogServiceProvider.php +++ b/src/Logging/MailableLogServiceProvider.php @@ -66,7 +66,6 @@ protected function setupViews(Container $app) public function register() { if ($this->app['log'] instanceof LogManager) { - $this->loadViewsFrom(base_path('designmynight/resources/views'), 'mailablelog'); $this->app['log']->extend('mail', function (Container $app, array $config) { $logger = new MailableLogger(); From 9b94476c4da991f0bef2e2503a809129aac19b8e Mon Sep 17 00:00:00 2001 From: Steve Porter Date: Sun, 9 Sep 2018 07:25:06 +0000 Subject: [PATCH 4/9] Apply fixes from StyleCI --- src/Logging/Monolog/Handlers/MailableHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Logging/Monolog/Handlers/MailableHandler.php b/src/Logging/Monolog/Handlers/MailableHandler.php index f0b7d2b..d6c1de1 100644 --- a/src/Logging/Monolog/Handlers/MailableHandler.php +++ b/src/Logging/Monolog/Handlers/MailableHandler.php @@ -15,7 +15,7 @@ class MailableHandler extends MailHandler * @param Mailable $mailable * @param LineFormatter $subjectFormatter * @param int $level The minimum logging level at which this handler will be triggered - * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not + * @param bool $bubble Whether the messages that are handled can bubble up the stack or not * * @return void */ From bc712b9cdd670abdc2b44169b1494256b8764821 Mon Sep 17 00:00:00 2001 From: Steve Porter Date: Fri, 14 Sep 2018 22:37:26 +0100 Subject: [PATCH 5/9] feat: add readme image --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0a6ed28..7b14a7c 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,9 @@ Laravel Mail Logger A service provider to add support for logging via email using Laravels built-in mail provider +![image](https://user-images.githubusercontent.com/12199424/45576336-a93c1300-b86e-11e8-9575-d1e4c5ed5dec.png) + + Table of contents ----------------- * [Installation](#installation) @@ -74,7 +77,7 @@ To ensure all unhandled exceptions are mailed, set up a mail logging channel and 'name' => 'Errors' ], // Optionally overwrite the mailable template - 'mailable' => NewLogMailable::class + // 'mailable' => NewLogMailable::class ], ], ``` From 149f4b913c82125f52ddc1de4d620742ec6b1fd7 Mon Sep 17 00:00:00 2001 From: Karel Faille Date: Wed, 19 Feb 2020 02:35:43 +0100 Subject: [PATCH 6/9] feat: rework of the package & Laravel 6 / 7 support Thanks to @jbeales https://github.com/designmynight/laravel-log-mailer/pull/7 --- CHANGELOG.md | 13 ++- README.md | 61 ++++++----- composer.json | 26 +++-- config/mailablelog.php | 28 ----- resources/views/log.blade.php | 5 - src/Logging/MailableLogServiceProvider.php | 78 -------------- .../Monolog/Handlers/MailableHandler.php | 56 ---------- src/{Logging => }/Mail/Log.php | 5 +- src/MailLogChannelServiceProvider.php | 25 +++++ .../MailableLogger.php => MailLogger.php} | 102 ++++++++++-------- src/Monolog/Formatters/HtmlFormatter.php | 17 +++ src/Monolog/Handlers/MailableHandler.php | 71 ++++++++++++ 12 files changed, 241 insertions(+), 246 deletions(-) delete mode 100644 config/mailablelog.php delete mode 100644 resources/views/log.blade.php delete mode 100644 src/Logging/MailableLogServiceProvider.php delete mode 100644 src/Logging/Monolog/Handlers/MailableHandler.php rename src/{Logging => }/Mail/Log.php (60%) create mode 100644 src/MailLogChannelServiceProvider.php rename src/{Logging/Driver/MailableLogger.php => MailLogger.php} (56%) create mode 100644 src/Monolog/Formatters/HtmlFormatter.php create mode 100644 src/Monolog/Handlers/MailableHandler.php diff --git a/CHANGELOG.md b/CHANGELOG.md index c8cd9df..b48dc41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,21 @@ # Changelog -All notable changes to `laravel-log-mailer` will be documented in this file +All notable changes to `laravel-mail-log-channel` will be documented in this file + +## 1.1.0 - 2020-01-29 + +- add support for Laravel 6 and 7 (thanks to @jbeales https://github.com/designmynight/laravel-log-mailer/pull/7) +- remove extra configuration and view files +- improve exception layout in mails ## 1.0.2 - 2018-09-09 + - fix logging levels ## 1.0.1 - 2018-09-05 + - fix dependancy ## 1.0.0 - 2018-09-04 -- initial release \ No newline at end of file + +- initial release diff --git a/README.md b/README.md index 7b14a7c..cac339c 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,15 @@ Laravel Mail Logger =============== -[![Latest Stable Version](http://img.shields.io/github/release/designmynight/laravel-log-mailer.svg)](https://packagist.org/packages/designmynight/laravel-log-mailer) [![Total Downloads](http://img.shields.io/packagist/dm/designmynight/laravel-log-mailer.svg)](https://packagist.org/packages/designmynight/laravel-log-mailer) +[![Latest Stable Version](http://img.shields.io/github/release/shaffe/laravel-mail-log-channel.svg)](https://packagist.org/packages/shaffe/laravel-mail-log-channel) [![Total Downloads](http://img.shields.io/packagist/dm/shaffe/laravel-mail-log-channel.svg)](https://packagist.org/packages/shaffe/laravel-mail-log-channel) [![StyleCI](https://github.styleci.io/repos/147424037/shield?branch=master)](https://github.styleci.io/repos/147424037) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) -A service provider to add support for logging via email using Laravels built-in mail provider +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](https://packagist.org/packages/designmynight/laravel-log-mailer) by Steve Porter. + +**This fork introduces some breaking changes. If you're upgrading from it, please follow the [configuration](#configuration) bellow.** ![image](https://user-images.githubusercontent.com/12199424/45576336-a93c1300-b86e-11e8-9575-d1e4c5ed5dec.png) @@ -18,69 +22,76 @@ Table of contents Installation ------------ -Installation using composer: +You can install this package via composer using this commande: ```sh -composer require designmynight/laravel-log-mailer +composer require shaffe/laravel-mail-log-channel ``` + ### Laravel version Compatibility Laravel | Package | :---------|:--------| + 7.x | 2.0.x | + 6.x | 2.0.x | 5.6.x | 1.0.x | - -And add the service provider in `config/app.php`: - -```php -DesignMyNight\Laravel\Logging\MailableLogServiceProvider::class, -``` + +The package will automatically register itself if you use Laravel. For usage with [Lumen](http://lumen.laravel.com), add the service provider in `bootstrap/app.php`. ```php -$app->register(DesignMyNight\Laravel\Logging\MailableLogServiceProvider::class); +$app->register(Shaffe\MailLogChannel\MailLogChannelServiceProvider::class); ``` Configuration ------------ -Most configuration options can be automatically populated by environment variables or in config/mailablelog.php, to generate it run php artisan vendor:publish. +To ensure all unhandled exceptions are mailed: -To ensure all unhandled exceptions are mailed, set up a mail logging channel and add it to your logging stack in config/logging.php: +1. create a `mail` logging channel in `config/logging.php`, +2. add this `mail` channel to your current logging stack, +3. add a `LOG_MAIL_ADDRESS` to your `.env` file to define the recipient. ```php 'channels' => [ 'stack' => [ 'driver' => 'stack', - // Add mail to the stack: + // 2. Add mail to the stack: 'channels' => ['single', 'mail'], ], // ... - // Create a mail logging channel: + // 1. Create a mail logging channel: 'mail' => [ 'driver' => 'mail', + 'level' => env('LOG_MAIL_LEVEL', 'notice'), + // Specify who to mail the log to 'to' => [ [ - 'address' => 'errors@designmynight.com', + 'address' => env('LOG_MAIL_ADDRESS'), 'name' => 'Error' ] ], - // Optionally specify who the log mail was sent by - // This is overidable in config/mailablelog.php and - // falls back to your global from in config/mail.php - 'from' => [ - 'address' => 'errors@designmynight.com', - 'name' => 'Errors' - ], + + // Optionally overwrite the sender. + // Default is config('mail.from.address') and config('mail.from.name') + // 'from' => [ + // 'address' => env('LOG_MAIL_ADDRESS'), + // '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 ], ], ``` -You can specify multiple channels and change the recipients and customise the email template per channel. - +You can specify multiple channels and change the recipients and customize the email template per channel. diff --git a/composer.json b/composer.json index e0cc2fb..60fd1e2 100644 --- a/composer.json +++ b/composer.json @@ -1,24 +1,36 @@ { - "name": "designmynight/laravel-log-mailer", + "name": "shaffe/laravel-mail-log-channel", "description": "A package to support logging via email in Laravel", - "homepage": "https://github.com/designmynight/laravel-log-mailer", + "homepage": "https://github.com/shaffe-fr/laravel-mail-log-channel", "license": "MIT", "keywords": [ "laravel", - "laravel-logging", + "logging", + "mail channel", "laravel-log-mailer", "monolog", - "designmynight" + "laravel-mail-log-channel", + "shaffe" ], "require": { - "illuminate/support": "^5.6" + "illuminate/bus": "^5.6|^6.0|^7.0", + "illuminate/contracts": "^5.6|^6.0|^7.0", + "illuminate/log": "^5.6|^6.0|^7.0", + "illuminate/mail": "^5.6|^6.0|^7.0", + "illuminate/queue": "^5.6|^6.0|^7.0", + "illuminate/support": "^5.6|^6.0|^7.0" }, "autoload": { "psr-4": { - "DesignMyNight\\Laravel\\": "src" + "Shaffe\\MailLogChannel\\": "src" } }, "authors": [ + { + "name": "Karel FAILLE", + "email": "shaffe.fr@gmail.com", + "role": "Developer" + }, { "name": "Steve Porter", "email": "steve@designmynight.com", @@ -28,7 +40,7 @@ "extra": { "laravel": { "providers": [ - "DesignMyNight\\Laravel\\Logging\\MailableLogServiceProvider" + "Shaffe\\MailLogChannel\\MailLogChannelServiceProvider" ] } } diff --git a/config/mailablelog.php b/config/mailablelog.php deleted file mode 100644 index a9c1990..0000000 --- a/config/mailablelog.php +++ /dev/null @@ -1,28 +0,0 @@ - env('MAILABLE_LOG_SUBJECT_FORMAT', '[%datetime%] %level_name%: %message%'), - - /* - |-------------------------------------------------------------------------- - | From information - |-------------------------------------------------------------------------- - | - | Set default from information of your mailables. The from information - | falls back to your mail config. - | - */ - 'from' => [ - 'address' => env('MAILABLE_LOG_FROM_ADDRESS'), - 'name' => env('MAILABLE_LOG_FROM_NAME'), - ], -]; diff --git a/resources/views/log.blade.php b/resources/views/log.blade.php deleted file mode 100644 index 2702b2f..0000000 --- a/resources/views/log.blade.php +++ /dev/null @@ -1,5 +0,0 @@ -@component('mail::message') - -{!!$content!!} - -@endcomponent diff --git a/src/Logging/MailableLogServiceProvider.php b/src/Logging/MailableLogServiceProvider.php deleted file mode 100644 index d4a1a7b..0000000 --- a/src/Logging/MailableLogServiceProvider.php +++ /dev/null @@ -1,78 +0,0 @@ -setupViews($this->app); - $this->setupConfig($this->app); - } - - /** - * Setup the config. - * - * @param \Illuminate\Contracts\Container\Container $app - * - * @return void - */ - protected function setupConfig(Container $app) - { - if ($app instanceof LaravelApplication && $app->runningInConsole()) { - $this->publishes([ - __DIR__.'/../../config/mailablelog.php' => config_path('mailablelog.php'), - ], 'mailablelog-config'); - } elseif ($app instanceof LumenApplication) { - $app->configure('mailablelog'); - } - } - - /** - * Publish the views. - * - * @param \Illuminate\Contracts\Container\Container $app - * - * @return void - */ - protected function setupViews(Container $app) - { - $this->loadViewsFrom(__DIR__.'/../../resources/views', 'mailablelog'); - - if ($this->app->runningInConsole()) { - $this->publishes([ - __DIR__.'/../../resources/views' => resource_path('views/vendor/mailablelog'), - ], 'mailablelog-views'); - } - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - if ($this->app['log'] instanceof LogManager) { - $this->loadViewsFrom(base_path('designmynight/resources/views'), 'mailablelog'); - - $this->app['log']->extend('mail', function (Container $app, array $config) { - $logger = new MailableLogger(); - - return $logger($config); - }); - } - } -} diff --git a/src/Logging/Monolog/Handlers/MailableHandler.php b/src/Logging/Monolog/Handlers/MailableHandler.php deleted file mode 100644 index d6c1de1..0000000 --- a/src/Logging/Monolog/Handlers/MailableHandler.php +++ /dev/null @@ -1,56 +0,0 @@ -mailer = app()->make('mailer'); - $this->subjectFormatter = $subjectFormatter; - $this->mailable = $mailable; - } - - /** - * Set the subject. - * - * @param array $records - * - * @return void - */ - protected function setSubject(array $records) - { - $this->mailable->subject($this->subjectFormatter->format($this->getHighestRecord($records))); - } - - /** - * {@inheritdoc} - */ - protected function send($content, array $records) - { - $this->mailable->with([ - 'content' => $content, - 'records' => $records, - ]); - - $this->setSubject($records); - - $this->mailer->send($this->mailable); - } -} diff --git a/src/Logging/Mail/Log.php b/src/Mail/Log.php similarity index 60% rename from src/Logging/Mail/Log.php rename to src/Mail/Log.php index a32cf79..387ad6a 100644 --- a/src/Logging/Mail/Log.php +++ b/src/Mail/Log.php @@ -1,10 +1,11 @@ markdown('mailablelog::log'); + return $this->markdown('mail::message', ['slot' => new HtmlString($this->viewData['content'] ?? '')]); } } diff --git a/src/MailLogChannelServiceProvider.php b/src/MailLogChannelServiceProvider.php new file mode 100644 index 0000000..9789373 --- /dev/null +++ b/src/MailLogChannelServiceProvider.php @@ -0,0 +1,25 @@ +app['log'] instanceof LogManager) { + $this->app['log']->extend('mail', function ($app, array $config) { + $logger = new MailLogger(); + + return $logger($config); + }); + } + } +} diff --git a/src/Logging/Driver/MailableLogger.php b/src/MailLogger.php similarity index 56% rename from src/Logging/Driver/MailableLogger.php rename to src/MailLogger.php index a31008e..e6aa947 100644 --- a/src/Logging/Driver/MailableLogger.php +++ b/src/MailLogger.php @@ -1,26 +1,37 @@ config = $config; + if (isset($config['level'])) { + $config['level'] = Logger::toMonologLevel($config['level']); + } + + $this->config = array_merge( + ['level' => Logger::DEBUG, 'bubble' => true], + $config + ); $mailHandler = new MailableHandler( $this->buildMailable(), @@ -34,50 +45,18 @@ public function __invoke(array $config) return new Logger('mailable', [$mailHandler]); } - /** - * Get the default from address. - * - * @return string - */ - protected function defaultFromAddress(): string - { - return config('mailablelog.from.address') ?? config('mail.from.address'); - } - - /** - * Get the default from name. - * - * @return string - */ - protected function defaultFromName(): string - { - return config('mailablelog.from.name') ?? config('mail.from.name'); - } - - /** - * Get the subject formatter. - * - * @return LineFormatter - */ - protected function subjectFormatter(): LineFormatter - { - $format = $this->config('subject_format') ?? config('mailablelog.subject_format'); - - return new LineFormatter($format); - } - /** * Create the mailable log. * - * @return Mailable + * @return \Illuminate\Contracts\Mail\Mailable */ protected function buildMailable(): Mailable { $mailable = $this->config('mailable') ?? MailableLog::class; $mailable = new $mailable(); - if (empty($recipients = $this->config('to'))) { - throw new InvalidArgumentException('To addresses required'); + if (! ($recipients = $this->config('to'))) { + throw new InvalidArgumentException('"To" address is required.'); } foreach ($recipients as $recipient) { @@ -87,6 +66,10 @@ protected function buildMailable(): Mailable ); } + if (! $this->defaultFromAddress()) { + throw new InvalidArgumentException('"From" address is required. Please check the `from.address` driver\'s config and the `mail.from.address` config.'); + } + $mailable->from( $this->config('from')['address'] ?? $this->defaultFromAddress(), $this->config('from')['name'] ?? $this->defaultFromName() @@ -95,10 +78,43 @@ protected function buildMailable(): Mailable return $mailable; } + + /** + * Get the default from address. + * + * @return string + */ + protected function defaultFromAddress(): ?string + { + return config('mail.from.address'); + } + + /** + * Get the default from name. + * + * @return string + */ + protected function defaultFromName(): ?string + { + return config('mail.from.name'); + } + + /** + * Get the subject formatter. + * + * @return \Monolog\Formatter\LineFormatter + */ + protected function subjectFormatter(): LineFormatter + { + $format = $this->config('subject_format') ?? '[%datetime%] %level_name%: %message%'; + + return new LineFormatter($format); + } + /** * Get the value from the passed in config. * - * @param string $field + * @param string $field * * @return mixed */ diff --git a/src/Monolog/Formatters/HtmlFormatter.php b/src/Monolog/Formatters/HtmlFormatter.php new file mode 100644 index 0000000..63cc40f --- /dev/null +++ b/src/Monolog/Formatters/HtmlFormatter.php @@ -0,0 +1,17 @@ + ' 'buildRecipients())) { + throw new InvalidArgumentException('"To" address is required. Please check the `to` driver\'s logging config.'); } - foreach ($recipients as $recipient) { - $mailable->to( - $recipient['address'], - $recipient['name'] - ); - } + $mailable->to($recipients); - if (! $this->defaultFromAddress()) { + if (! $this->defaultFromAddress() && ! isset($this->config('from')['address'])) { throw new InvalidArgumentException('"From" address is required. Please check the `from.address` driver\'s config and the `mail.from.address` config.'); } @@ -78,6 +74,37 @@ protected function buildMailable(): Mailable return $mailable; } + protected function buildRecipients(): array + { + if (! ($to = $this->config('to'))) { + return []; + } + + $recipients = []; + foreach ((array)$to as $emailOrIndex => $nameOrEmail) { + if (is_array($nameOrEmail)) { + $email = $nameOrEmail['email'] ?? $nameOrEmail['address'] ?? null; + if ($email) { + $recipients[] = [ + 'email' => $email, + 'name' => $nameOrEmail['name'] ?? null, + ]; + } + } elseif (is_string($emailOrIndex)) { + $recipients[] = [ + 'email' => $emailOrIndex, + 'name' => $nameOrEmail, + ]; + } elseif (is_string($nameOrEmail)) { + $recipients[] = [ + 'email' => $nameOrEmail, + 'name' => null, + ]; + } + } + + return $recipients; + } /** * Get the default from address. From 0552469fc3786f9f4fe91ae5900a2a5229d7d2f9 Mon Sep 17 00:00:00 2001 From: Karel FAILLE Date: Thu, 27 Feb 2020 13:24:33 +0100 Subject: [PATCH 8/9] doc: update README badges --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 76631a5..42ee32e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ Laravel Mail Logger =============== -[![Latest Stable Version](http://img.shields.io/github/release/shaffe/laravel-mail-log-channel.svg)](https://packagist.org/packages/shaffe/laravel-mail-log-channel) [![Total Downloads](http://img.shields.io/packagist/dm/shaffe/laravel-mail-log-channel.svg)](https://packagist.org/packages/shaffe/laravel-mail-log-channel) -[![StyleCI](https://github.styleci.io/repos/147424037/shield?branch=master)](https://github.styleci.io/repos/147424037) +[![Latest Stable Version](https://img.shields.io/github/v/release/shaffe-fr/laravel-mail-log-channel.svg)](https://packagist.org/packages/shaffe/laravel-mail-log-channel) [![Total Downloads](https://img.shields.io/packagist/dt/shaffe/laravel-mail-log-channel.svg)](https://packagist.org/packages/shaffe/laravel-mail-log-channel) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) A service provider to add support for logging via email using Laravels built-in mail provider. From cc290b81a002c0122d07442ea25f58a15b433828 Mon Sep 17 00:00:00 2001 From: Karel FAILLE Date: Thu, 27 Feb 2020 14:05:58 +0100 Subject: [PATCH 9/9] doc: update README and CHANGELOG --- CHANGELOG.md | 8 ++++++-- README.md | 44 ++++++++++++++++++++++---------------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b48dc41..ce878a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,12 @@ # Changelog -All notable changes to `laravel-mail-log-channel` will be documented in this file +All notable changes to `laravel-mail-log-channel` will be documented in this file. -## 1.1.0 - 2020-01-29 +## 2.0.1 - 2020-02-21 + +- support multiple `to` configuration formats + +## 2.0.0 - 2020-01-29 - add support for Laravel 6 and 7 (thanks to @jbeales https://github.com/designmynight/laravel-log-mailer/pull/7) - remove extra configuration and view files diff --git a/README.md b/README.md index 42ee32e..b2c6690 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -Laravel Mail Logger -=============== +# Laravel Mail Log Channel + [![Latest Stable Version](https://img.shields.io/github/v/release/shaffe-fr/laravel-mail-log-channel.svg)](https://packagist.org/packages/shaffe/laravel-mail-log-channel) [![Total Downloads](https://img.shields.io/packagist/dt/shaffe/laravel-mail-log-channel.svg)](https://packagist.org/packages/shaffe/laravel-mail-log-channel) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) @@ -10,14 +10,12 @@ This package is a fork of [laravel-log-mailer](https://packagist.org/packages/de ![image](https://user-images.githubusercontent.com/12199424/45576336-a93c1300-b86e-11e8-9575-d1e4c5ed5dec.png) +## Table of contents -Table of contents ------------------ * [Installation](#installation) * [Configuration](#configuration) -Installation ------------- +## Installation You can install this package via composer using this commande: @@ -25,15 +23,14 @@ You can install this package via composer using this commande: composer require shaffe/laravel-mail-log-channel ``` - -### Laravel version Compatibility +### Laravel version compatibility Laravel | Package | :---------|:--------| - 7.x | 1.1.x | - 6.x | 1.1.x | - 5.6.x | 1.0.x | - + 7.x | ^2.0 | + 6.x | ^2.0 | + 5.6.x | ^1.0 | + The package will automatically register itself if you use Laravel. For usage with [Lumen](http://lumen.laravel.com), add the service provider in `bootstrap/app.php`. @@ -42,8 +39,7 @@ For usage with [Lumen](http://lumen.laravel.com), add the service provider in `b $app->register(Shaffe\MailLogChannel\MailLogChannelServiceProvider::class); ``` -Configuration ------------- +## Configuration To ensure all unhandled exceptions are mailed: @@ -51,6 +47,8 @@ To ensure all unhandled exceptions are mailed: 2. add this `mail` channel to your current logging stack, 3. 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. + ```php 'channels' => [ 'stack' => [ @@ -66,21 +64,23 @@ To ensure all unhandled exceptions are mailed: 'driver' => 'mail', 'level' => env('LOG_MAIL_LEVEL', 'notice'), - // Specify who to mail the log to + // Specify mail recipient 'to' => [ [ 'address' => env('LOG_MAIL_ADDRESS'), - 'name' => 'Error' - ] + '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%'), + // '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` @@ -89,6 +89,8 @@ To ensure all unhandled exceptions are mailed: ], ``` +### Recipients configuration format + The following `to` config formats are supported: * single email address: @@ -103,13 +105,13 @@ The following `to` config formats are supported: 'to' => explode(',', env('LOG_MAIL_ADDRESS', '')), ``` -* associative array of email/name addresses: +* associative array of email => name addresses: ```php 'to' => [env('LOG_MAIL_ADDRESS', '') => 'Error'],` ``` -* an array of email and name: +* array of email and name: ```php 'to' => [ @@ -119,5 +121,3 @@ The following `to` config formats are supported: ], ], ``` - -You can specify multiple channels and change the recipients and customize the email template per channel.