Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 6 Support #7

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
17 changes: 15 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
# 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.

## 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
- 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

- initial release
105 changes: 71 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,86 +1,123 @@
Laravel Mail Logger
===============
# Laravel Mail Log Channel

[![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)
[![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
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.

![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

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 version compatibility

Laravel | Package |
:---------|:--------|
5.6.x | 1.0.x |

And add the service provider in `config/app.php`:
7.x | ^2.0 |
6.x | ^2.0 |
5.6.x | ^1.0 |

```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
------------
## 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.

You can specify multiple channels and individually change the recipients, the subject and the email template.

```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',
// Specify who to mail the log to
'level' => env('LOG_MAIL_LEVEL', 'notice'),

// Specify mail recipient
'to' => [
[
'address' => 'errors@designmynight.com',
'name' => 'Error'
]
'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',
// 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
],
],
```

You can specify multiple channels and change the recipients and customise the email template per channel.
### Recipients configuration format

The following `to` config formats are supported:

* single email address:

```php
'to' => env('LOG_MAIL_ADDRESS', ''),
```

* array of email addresses:

```php
'to' => explode(',', env('LOG_MAIL_ADDRESS', '')),
```

* associative array of email => name addresses:

```php
'to' => [env('LOG_MAIL_ADDRESS', '') => 'Error'],`
```

* array of email and name:

```php
'to' => [
[
'address' => env('LOG_MAIL_ADDRESS', ''),
'name' => 'Error',
],
],
```
26 changes: 19 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -28,7 +40,7 @@
"extra": {
"laravel": {
"providers": [
"DesignMyNight\\Laravel\\Logging\\MailableLogServiceProvider"
"Shaffe\\MailLogChannel\\MailLogChannelServiceProvider"
]
}
}
Expand Down
28 changes: 0 additions & 28 deletions config/mailablelog.php

This file was deleted.

5 changes: 0 additions & 5 deletions resources/views/log.blade.php

This file was deleted.

5 changes: 4 additions & 1 deletion src/Logging/Driver/MailableLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 0 additions & 1 deletion src/Logging/MailableLogServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/Logging/Monolog/Handlers/MailableHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/Logging/Mail/Log.php → src/Mail/Log.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

namespace DesignMyNight\Laravel\Logging\Mail;
namespace Shaffe\MailLogChannel\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\HtmlString;

class Log extends Mailable
{
Expand All @@ -17,6 +18,6 @@ class Log extends Mailable
*/
public function build()
{
return $this->markdown('mailablelog::log');
return $this->markdown('mail::message', ['slot' => new HtmlString($this->viewData['content'] ?? '')]);
}
}
25 changes: 25 additions & 0 deletions src/MailLogChannelServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Shaffe\MailLogChannel;

use Illuminate\Log\LogManager;
use Illuminate\Support\ServiceProvider;

class MailLogChannelServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
if ($this->app['log'] instanceof LogManager) {
$this->app['log']->extend('mail', function ($app, array $config) {
$logger = new MailLogger();

return $logger($config);
});
}
}
}
Loading