定制 kaoken/laravel-mysql-email-log 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kaoken/laravel-mysql-email-log

Composer 安装命令:

composer require kaoken/laravel-mysql-email-log

包简介

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

README 文档

README

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

Travis composer version licence laravel version

Table of content

Install

composer:

composer require kaoken/laravel-mysql-email-log

or, add composer.json

  "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.

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 to email_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

LOG_CHANNEL=mysql_log

Command

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

After execution, the following directories and files are added.

  • 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.

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.

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.

Event

See inside the vendor\laravel-mysql-email-log\src\Events directory!

BeforeWriteLogEvent

Called before writing the log.

License

MIT

kaoken/laravel-mysql-email-log 适用场景与选型建议

kaoken/laravel-mysql-email-log 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 09 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「email」 「mysql」 「monolog」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 kaoken/laravel-mysql-email-log 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kaoken/laravel-mysql-email-log 我们能提供哪些服务?
定制开发 / 二次开发

基于 kaoken/laravel-mysql-email-log 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 30
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-20