定制 consilience/laravel-slow-query-logger 二次开发

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

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

consilience/laravel-slow-query-logger

Composer 安装命令:

composer require consilience/laravel-slow-query-logger

包简介

Slow Query Logger for Laravel

README 文档

README

Latest Stable Version Latest Unstable Version License Total Downloads

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 users set name = ?, users.updated_at = ? where id = ?

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 users set name = 'JJ', users.updated_at = '2022-08-02 16:17:05' where id = '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 users set name = 'JJ', users.updated_at = '2022-08-02 22:21:50' where id = '1' {"bindings":["JJ","2022-08-02 22:21:50",1]}

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固