GithubHelp home page GithubHelp logo

consilience / laravel-slow-query-logger Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rokde/laravel-slow-query-logger

0.0 1.0 1.0 18 KB

Slow Query Logger for Laravel 5.6 to 9

License: MIT License

PHP 100.00%

laravel-slow-query-logger's Introduction

Slow Query Logger for Laravel

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]}

laravel-slow-query-logger's People

Contributors

judgej avatar

Watchers

 avatar

Forkers

elarmust

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.