wimski / laravel-query-logger

Laravel Query Logger

Repository from Github https://github.comwimski/laravel-query-loggerRepository from Github https://github.comwimski/laravel-query-logger

⚠️ THIS PROJECT IS CURRENTLY A WIP AND CANNOT BE INSTALLED THROUGH COMPOSER (YET)! ⚠️

Laravel Query Logger

A Laravel package for writing (SQL) database queries to a log channel for local debugging.

Installation

You can install the package via composer:

composer require --dev wimski/laravel-query-logger

The package is loaded using Package Discovery, when disabled read Manual Installation.

Configuration

General

Name Default Value Description
QUERY_LOGGER_ENABLED false Whether the logging of queries is enabled.
QUERY_LOGGER_CLEAR_ON_EVERY_REQUEST false Whether to clear the log before every request. This can be useful if you have a controlled request cycle and only want to see the logged queries of the last request.

Channel

Name Default Value Description
QUERY_LOGGER_CHANNEL_NAME query The name of the log channel.
QUERY_LOGGER_DRIVER single The driver of the log channel.
QUERY_LOGGER_LEVEL debug The level of the log channel.
QUERY_LOGGER_PATH logs/query.log The path the log file will be written to within the /storage directory. This is used in combination with default single driver.

Custom Channel

A log channel is created dynamically with the values above. If you want to have more control over the log channel, for example because of a custom driver, you can publish the query-logger.php config and replace the channel_data entry with entirely custom configuration. You could still use some of the environment variables. When you directly create a log channel in logging.php with the name specified in QUERY_LOGGER_CHANNEL_NAME, your custom channel won't be overwritten.

Rules

Name Default Value Description
QUERY_LOGGER_MINIMUM_DURATION 0 Only queries with a duration longer than this value will be logged. This is useful to only log very slow queries.
QUERY_LOGGER_MATCH_PATTERN /^(select|insert|update|delete)((?!migration).)*/i The regular expression pattern a query must match in order to be logged.

Custom Rules

The rules entry in the query-logger.php config contains two default rules, which are controlled by the values above. If you want to add custom rules or remove default ones, simply publish the config of this package and add you own classes. Your custom rule classes must implement the Wimski\LaravelQueryLogger\Providers\Contracts\Rules\RuleInterfaceinterface. The rules are applied in order, so it's best to put 'cheaper' rules on top for efficient early returns.

Manual Installation

When disabled, register the LaravelQueryLoggerServiceProvider manually by adding it to your config/app.php

/*
 * Package Service Providers...
 */
 Wimski\LaravelQueryLogger\QueryLoggerServiceProvider::class,

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Laravel Query Logger

License:MIT License


Languages

Language:PHP 100.0%