silverd/laravel-sql-logger
Composer 安装命令:
composer require silverd/laravel-sql-logger
包简介
Log SQL queries in Laravel/Lumen framework
README 文档
README
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.
Support
Using this package is free of charge, however to keep it up-to-date and add new features small money support is appreciated. Suggested amount is 5$ per project where you use this package but any amount will help further development of this package.
(you are free to change amount on Paypal page)
Installation
-
Run
composer require mnabialek/laravel-sql-logger --devin console to install this module (Notice
--devflag - it's recommended to use this package only for development). -
If you use Laravel < 5.5 open
config/app.phpand inproviderssection 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.phpand add:$app->register(Mnabialek\LaravelSqlLogger\Providers\ServiceProvider::class);
-
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
.envfile by default.For Lumen you should skip this step.
-
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.sampleit's also recommended to add those entries also in.env.samplefile just to make sure everyone know about those env variables. Be aware thatSQL_LOGGER_DIRECTORYis directory inside storage directory. If you want you can change it editingconfig/sql_logger.phpfile.To find out more about those setting please take a look at Configuration file
-
Make sure directory specified in
.envfile 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) -
Make sure on live server you will set logging SQL queries to false in your
.envfile. 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.
silverd/laravel-sql-logger 适用场景与选型建议
silverd/laravel-sql-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.71k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「sql」 「logger」 「laravel」 「sql log」 「lumen」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 silverd/laravel-sql-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 silverd/laravel-sql-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 silverd/laravel-sql-logger 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Query filtering in your frontend
Workflow logger
HTTP request logger middleware for Laravel
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Laravel 5.x.x library for integration Monolog Sentry
High-performance, zero-dependency PSR-3 logger for MonkeysLegion with structured logging, handlers, processors, and PHP 8.4 features.
统计信息
- 总下载量: 5.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-24