consilience/laravel-slow-query-logger
Composer 安装命令:
composer require consilience/laravel-slow-query-logger
包简介
Slow Query Logger for Laravel
README 文档
README
Installation/Quickstart
composer require consilience/laravel-slow-query-logger
or add the following line to composer.json then run composer update:
"require": { "consilience/laravel-slow-query-logger": "^2.0" }
Turn on slow query logging:
LARAVEL_SLOW_QUERY_LOGGER_ENABLED=true
Look into your log file to see your slow queries.
Configuration
The configuration file can be published with the following command:
php artisan vendor:publish --provider="Consilience\Laravel\SlowQueryLogger\SlowQueryLoggerProvider"
You will likely not need to publish the config; just set required environment variables as listed below.
enabled
Enable the slow queries logger.
You can set this value through environment variable LARAVEL_SLOW_QUERY_LOGGER_ENABLED.
It is false by default.
channel
Sets the channel to log in. This can be handy if you want to keep all query logs separate from other log messages.
You can set this value through environment variable LARAVEL_SLOW_QUERY_LOGGER_CHANNEL.
By default, the application default logging channel will be used.
level
Set the log-level for logging the slow queries.
You can set this value through environment variable LARAVEL_SLOW_QUERY_LOGGER_LEVEL.
It is debug by default.
threshold-ms
Only log queries that take longer than this number of milliseconds to complete.
You can set this value through environment variable LARAVEL_SLOW_QUERY_LOGGER_THRESHOLD_MS.
It is 700 by default.
A value of 0 will log all queries.
Usage
By default, bind variables are not included in the logged details. Just the core query is logged:
[20[2022-08-02 22:15:33] production.DEBUG: SQL 6663.970 mS: update
userssetname= ?,users.updated_at= ? whereid= ?
By setting LARAVEL_SLOW_QUERY_LOGGER_REPLACE_BINDINGS=true the query will have its bind variables
substituted with the matching values:
[2022-08-02 16:17:13] production.DEBUG: SQL 784.200 mS: update
userssetname= 'JJ',users.updated_at= '2022-08-02 16:17:05' whereid= '1'
You can also (or alternatively) list the bind data separately in the context of the log
by setting LARAVEL_SLOW_QUERY_LOGGER_SHOW_BINDINGS=true.
This may be useful to observe the data types in more detail, since substituting the bindings will treat
all values as strings.
[2022-08-02 22:22:35] production.DEBUG: SQL 413.910 mS: update
userssetname= 'JJ',users.updated_at= '2022-08-02 22:21:50' whereid= '1' {"bindings":["JJ","2022-08-02 22:21:50",1]}
consilience/laravel-slow-query-logger 适用场景与选型建议
consilience/laravel-slow-query-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.07k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 08 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 consilience/laravel-slow-query-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 consilience/laravel-slow-query-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-02