Giter VIP home page Giter VIP logo

laravel-mail-log-channel's Introduction

Laravel Mail Log Channel

Latest Stable Version Total Downloads License: MIT

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.

image

Table of contents

Installation

You can install this package via composer using this commande:

composer require shaffe/laravel-mail-log-channel

Laravel version compatibility

Laravel Package
6, 7, 8, 9, 10, 11 ^2.0
5.6.x ^1.0

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:

  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.

'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',
         ],
     ],

laravel-mail-log-channel's People

Contributors

dev-idsys-mi avatar jbeales avatar shaffe-fr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-mail-log-channel's Issues

Anyway of excluding a certain user?

How do I exclude a certain user so that the mail logging doesn't happen if I'm logged into the application as myself? I only need to be emailed and notified if someone other than myself has triggered an error.

Thanks

Segfault when used as part of stack driver

I'm having a problem where I get a segmentation fault when the mail channel is part of the stack driver in Laravel 9. This didn't happen in Laravel 8.

My default log channel is the stack driver with this config:

        'stack' => [
            'driver' => 'stack',
            'channels' => ['daily' , 'mail'],
            'ignore_exceptions' => false,
        ],

This is the config for my mail driver:

        'mail' => [
            'driver' => 'mail',
            'level'  => 'error',
            // Specify who to mail the log to
            'to' => [
                [
                    'address' => '[email protected]',
                    'name' => 'John B',
                ],
            ],
        ],

Then I run this artisan command, or trigger an error, and I get a segmentation fault:

Artisan::command('mail-log', function() {
    Log::error('Test Mail Error.');
});

I'm stepping through it in Xdebug and something within $this->mailer = app()->make('mailer'); on line 40 of src/Monolog/Handlers/MailableHandler.php seems to get into a recursive loop. I suspect something isn't resolving so we keep trying to build a new stack log driver, which builds a new mail log driver, which does't resolve making the mailer, so we build a new stack log driver, which builds a new mail log driver.... etc. I'm not sure if there's an error being thrown making the mail log channel, or it simply is getting passed a "null" somewhere, so defaults to the default log channel - which is the stack channel.

Update for Laravel 9

- shaffe/laravel-mail-log-channel v2.1.0 requires illuminate/queue ^5.6|^6.0|^7.0|^8.0

Seems that this breaks the Laravel 8 -> 9 upgrade...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.