confetticode/laravel-log-mail

Laravel - Sending log records via mail channels

v0.1.0 2024-10-17 07:22 UTC

This package is auto-updated.

Last update: 2024-11-17 07:37:48 UTC


README

Packagist Test Downloads

Supported PHP 8.2+ and Laravel 11+

Installation

composer require confetticode/laravel-log-mail

Usage

Configure a mail channel.

<?php

return [
    // ...
    'channels' => [
        'mail' => [
            'driver' => 'mail',
            'mailer' => env('LOG_MAIL_MAILER'),
            'name' => env('LOG_MAIL_NAME'),
            'level' => env('LOG_MAIL_LEVEL'),
            'bubble' => env('LOG_MAIL_BUBBLE'),
            'from' => [
                'address' => env('LOG_MAIL_FROM_ADDRESS'),
                'name' => env('LOG_MAIL_FROM_NAME'),
            ],
            'to' => [
                'address' => env('LOG_MAIL_TO_ADDRESS'),
                'name' => env('LOG_MAIL_TO_NAME'),
            ],
        ],
    ],
    // ...
];

Log an error via the mail channel.

<?php

use Illuminate\Support\Facades\Log;

try {
    new UndefinedClass;
} catch (\Throwable $e) {
    Log::channel('mail')->error($e->getMessage(), ['exception' => $e]);
}

Use the mail channel as a part of the log stack.

LOG_STACK=daily,mail

Contributing

Thank you for considering contributing to the Laravel Log Mail package! The contribution guide can be found in the contributing documentation.

License (MIT)

The MIT License (MIT). Please see the License for more information.