2017 © Pedro Peláez
 

library laravel-mysql-email-log

Save logs handled by Laravel in Mysql, and send mail when it is over specified level.

image

kaoken/laravel-mysql-email-log

Save logs handled by Laravel in Mysql, and send mail when it is over specified level.

  • Tuesday, January 9, 2018
  • by kaoken
  • Repository
  • 1 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

laravel-mysql-email-log

Save logs handled by Laravel in Mysql, and send mail when it is over specified level., (*1)

Travis composer version licence laravel version, (*2)

Table of content, (*3)

Install

composer:, (*4)

composer require kaoken/laravel-mysql-email-log

or, add composer.json, (*5)

  "require": {
    ...
    "kaoken/laravel-mysql-email-log":"^1.8.5"
  }

Setting

Add to config\app.php as follows:

    'providers' => [
        ...
        // Add
        Kaoken\LaravelMysqlEmailLog\LaravelMysqlEmailLogServiceProvider::class
    ],

Add to config\database.php as follows:

    'connections' => [
        ...
        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],
        // Add (Copy 'mysql' above)
        'mysql_log' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],
        ...

Copy the above ['connections']['mysql'] and set the driver name to mysql_log. This is necessary to prevent the log from being lost due to rollback after writing the log when doing transaction processing (DB :: transaction,DB :: beginTransaction etc.) with the driver name mysql., (*6)

Add to config\logging.php as follows:

  • driver is a monolog.
  • handler is a Kaoken\LaravelMysqlEmailLog\LaravelMysqlEmailLogHandler::class.
  • model is a log model.
  • email sends a mail according toemail_send_level if it is true. In case of false, do not send anything.
  • email_send_level specifies the log level and send from the specified log level or higher. Since the priority is low, DEBUGINFONOTICEWARNINGERRORCRITICALALERTEMERGENCY.Capital letters and lower case letters are not distinguished.
  • email_log should modify the class derived from Mailable as necessary. Send log mail.
  • email_send_limit should modify the class derived from Mailable as necessary. Send when e-mail transmission limit max_email_send_count is exceeded.
  • max_email_send_count, the log e-mail that can be transmitted in one day. A simple warning mail is sent when the number exceeds the number of transmissions. See email_send_level.
  • to is the destination of the mail.
    // Add
    'mysql_log' => [
        'driver' => 'monolog',
        'handler' => Kaoken\LaravelMysqlEmailLog\LaravelMysqlEmailLogHandler::class,
        'model' => Kaoken\LaravelMysqlEmailLog\Model\Log::class,
        'email' => true,
        'email_send_level' => 'ERROR',
        'email_log' => Kaoken\LaravelMysqlEmailLog\Mail\LogMailToAdmin::class,
        'email_send_limit' => Kaoken\LaravelMysqlEmailLog\Mail\SendLimitMailToAdmin::class,
        'max_email_send_count' => 64,
        'to' => 'hoge@hoge.com'
    ],

Modify .env to enable logging

Make corrections as follows, (*7)

LOG_CHANNEL=mysql_log

Command

php artisan vendor:publish --tag=mysql-email-log

After execution, the following directories and files are added., (*8)

  • database
    • migrations
    • 2017_09_17_000001_create_logs_table.php
  • resources
    • views
    • vendor
      • mysql_email_log
      • log.blade.php
      • over_limit.blade.php

Migration

Migration file 2017_09_17_000001_create_logs_table.php should be modified as necessary., (*9)

php artisan migrate

E-Mail

In the configuration config\logging.php of the above setting, The Kaoken\LaravelMysqlEmailLog\Mail\ConfirmationMailToUser::class of email_log is used as the log mail of the target level or higher. The template uses views\vendor\mysql_email_log\log.blade.php. Change according to the specifications of the application., (*10)

The Kaoken\LaravelMysqlEmailLog\Mail\ConfirmationMailToUser::class of email_send_limit is used when the log above the target level reaches the send limit. The template uses views\vendor\mysql_email_log\over_limit.blade.php. Change according to the specifications of the application., (*11)

Event

See inside the vendor\laravel-mysql-email-log\src\Events directory!, (*12)

BeforeWriteLogEvent

Called before writing the log., (*13)

License

MIT, (*14)

The Versions

09/01 2018

dev-master

9999999-dev https://github.com/kaoken/laravel-mysql-email-log

Save logs handled by Laravel in Mysql, and send mail when it is over specified level.

  Sources   Download

MIT

The Requires

 

laravel email monolog mysql

09/01 2018

1.0.5

1.0.5.0 https://github.com/kaoken/laravel-mysql-email-log

Save logs handled by Laravel in Mysql, and send mail when it is over specified level.

  Sources   Download

MIT

The Requires

 

laravel email monolog mysql

16/10 2017

1.0.4

1.0.4.0 https://github.com/kaoken/laravel-mysql-email-log

Save logs handled by Laravel in Mysql, and send mail when it is over specified level.

  Sources   Download

MIT

The Requires

 

laravel email monolog mysql

20/09 2017

1.0.3

1.0.3.0 https://github.com/kaoken/laravel-mysql-email-log

Save logs handled by Laravel in Mysql, and send mail when it is over specified level.

  Sources   Download

MIT

The Requires

 

laravel email monolog mysql