Package Data | |
---|---|
Maintainer Username: | BWT group |
Maintainer Contact: | chesanovskiydv@gmail.com (Chesanovskiy Denis) |
Package Create Date: | 2016-12-10 |
Package Last Update: | 2017-02-07 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:15:13 |
Package Statistics | |
---|---|
Total Downloads: | 6,728 |
Monthly Downloads: | 2 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This package allows to enable and set up email alerts in case errors appear.
Setup this package with composer using the following command:
composer require bwt-team/laravel-error-mailer
After composer update add service provider into providers
in config/app.php
.
BwtTeam\LaravelErrorMailer\Providers\ErrorMailerServiceProvider::class
This service provider will enable with an option to publish config file to update package settings depending on your needs. After publication this service provider can be disabled, it is not needed for package work. For publication please use:
php artisan vendor:publish --provider="BwtTeam\LaravelErrorMailer\Providers\ErrorMailerServiceProvider" --tag=config
Also, to make package work please register the setup class in bootstrap/app.php
. Registration should happen before Application sample is returned.
$app->bind(
\Illuminate\Foundation\Bootstrap\ConfigureLogging::class,
\BwtTeam\LaravelErrorMailer\ConfigureLogging::class
);
To send email messages you can use laravel component or create a class for sending yourself by initializing class, which implements \Swift_Transport interface. To set up laravel component:
composer require illuminate/mail
config
directory, which is stored in root catalogue (or create the directory yourself).vendor/bwt-team/laravel-error-mailer/config/error-mailer.php
into config directory, which is stored in root directory (or create it yourself if it is missing) and set it up according to your needs.bootstrap/app
.
$app->register(\Illuminate\Mail\MailServiceProvider::class);
$app->configure('mail'); $app->configure('error-mailer');
To enable sending email alerts you need to create a class instance \BwtTeam\LaravelErrorMailer\Configurators\MailConfigurator
in bootstrap/app
, its constructor looks like following:
public function __construct($subject, $to, $from, array $processors = [], $logLevel = Logger::ERROR, \Swift_Transport $sendmailTransport = null)
This class is responsible for sending alert emails by mail but enabling it will disable writing logs into file, which is enabled in lumen by default. In order not to disable
writing you need to create a class instance \BwtTeam\LaravelErrorMailer\Configurators\FileConfigurator
. Class constructor looks like the following:
public function __construct($file = null, $logLevel = Logger::DEBUG)
After that you need to pass this instance into with
method in \BwtTeam\LaravelErrorMailer\Configurators\MailConfigurator
class.
Each configuration class has options to work with monologue processors. For this you need to pass process instance to class name into constructor or add with the help of addProcessors
method.
In addition to standard monologue processors, the following out-of-box processors are available:
\BwtTeam\LaravelErrorMailer\Processors\SqlProcessor::class,
\BwtTeam\LaravelErrorMailer\Processors\PostDataProcessor::class,
\BwtTeam\LaravelErrorMailer\Processors\HeadersProcessor::class,
When component is set up you need to pass it to configureMonologUsing
method in Application class before it is returned.
Final setup will look like this:
$configurator = new \BwtTeam\LaravelErrorMailer\Configurators\MailConfigurator('subject', 'to@example.com', 'from@example.com');
$configurator->setSendmailTransport(\Swift_MailTransport::newInstance());
$configurator->addProcessors([
\BwtTeam\LaravelErrorMailer\Processors\SqlProcessor::class,
\BwtTeam\LaravelErrorMailer\Processors\PostDataProcessor::class,
\BwtTeam\LaravelErrorMailer\Processors\HeadersProcessor::class,
\Monolog\Processor\WebProcessor::class
]);
$configurator->with(new \BwtTeam\LaravelErrorMailer\Configurators\FileConfigurator());
$app->configureMonologUsing($configurator);
This package is using MIT.