mnabialek/laravel-sql-logger 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mnabialek/laravel-sql-logger

Composer 安装命令:

composer require mnabialek/laravel-sql-logger

包简介

Log SQL queries in Laravel/Lumen framework

README 文档

README

Packagist Tests codecov

This module allows you to log SQL queries (and slow SQL queries) to log file in Laravel/Lumen framework. It's useful mainly when developing your application to verify whether your queries are valid and to make sure your application doesn't run too many or too slow database queries.

Requirements

  • Laravel 5.8 - 12.x
  • Lumen 5.8 - 11.x (Lumen development discontinued after version 11)
  • PHP 7.4 - 8.5

Installation

  1. Run

    composer require mnabialek/laravel-sql-logger --dev

    in console to install this module (Notice --dev flag - it's recommended to use this package only for development).

  2. If you use Laravel < 5.5 open config/app.php and in providers section add:

    Mnabialek\LaravelSqlLogger\Providers\ServiceProvider::class,

    Laravel 5.5 uses Package Auto-Discovery and it will automatically load this service provider so you don't need to add anything into above file.

    If you are using Lumen open bootstrap/app.php and add:

    $app->register(Mnabialek\LaravelSqlLogger\Providers\ServiceProvider::class);
  3. If you use Laravel < 5.5 run:

    php artisan vendor:publish --provider="Mnabialek\LaravelSqlLogger\Providers\ServiceProvider"

    in your console to publish default configuration files.

    If you are using Laravel 5.5 run:

    php artisan vendor:publish

    and choose the number matching "Mnabialek\LaravelSqlLogger\Providers\ServiceProvider" provider.

    By default you should not edit published file because all the settings are loaded from .env file by default.

    For Lumen you should skip this step.

  4. In your .env file add the following entries:

    SQL_LOGGER_DIRECTORY="logs/sql"
    SQL_LOGGER_USE_SECONDS=false
    SQL_LOGGER_CONSOLE_SUFFIX=
    SQL_LOGGER_LOG_EXTENSION=".sql"
    SQL_LOGGER_ALL_QUERIES_ENABLED=true
    SQL_LOGGER_ALL_QUERIES_OVERRIDE=false
    SQL_LOGGER_ALL_QUERIES_PATTERN="#.*#i"
    SQL_LOGGER_ALL_QUERIES_FILE_NAME="[Y-m-d]-log"
    SQL_LOGGER_SLOW_QUERIES_ENABLED=true
    SQL_LOGGER_SLOW_QUERIES_MIN_EXEC_TIME=100
    SQL_LOGGER_SLOW_QUERIES_PATTERN="#.*#i"
    SQL_LOGGER_SLOW_QUERIES_FILE_NAME="[Y-m-d]-slow-log"
    SQL_LOGGER_FORMAT_NEW_LINES_TO_SPACES=false
    SQL_LOGGER_FORMAT_ENTRY_FORMAT="/* [origin]\\n   Query [query_nr] - [datetime] [[query_time]] */\\n[query]\\n[separator]\\n"
    

    and adjust values to your needs. You can skip variables for which you want to use default values.

    If you have also .env.sample it's also recommended to add those entries also in .env.sample file just to make sure everyone know about those env variables. Be aware that SQL_LOGGER_DIRECTORY is directory inside storage directory. If you want you can change it editing config/sql_logger.php file.

    To find out more about those setting please take a look at Configuration file

  5. Make sure directory specified in .env file exists in storage path and you have valid file permissions to create and modify files in this directory (If it does not exist this package will automatically create it when needed but it's recommended to create it manually with valid file permissions)

  6. Make sure on live server you will set logging SQL queries to false in your .env file. This package is recommended to be used only for development to not impact production application performance.

Upgrading from 1.*

When upgrading from 1.* version you should remove current sql_logger.php config file and replace this with new one (see installation step). You should also use new variables in .env file (old won't be used).

Authors

Author of this awesome package is Marcin Nabiałek and Contributors

Changes

All changes are listed in Changelog

License

This package is licenced under the MIT license however Support is more than welcome.

mnabialek/laravel-sql-logger 适用场景与选型建议

mnabialek/laravel-sql-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 817.92k 次下载、GitHub Stars 达 158, 最近一次更新时间为 2016 年 01 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 mnabialek/laravel-sql-logger 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 817.92k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 162
  • 点击次数: 20
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 158
  • Watchers: 5
  • Forks: 28
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-23