Download the PHP package elminson/db-logger without Composer
On this page you can find all versions of the php package elminson/db-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elminson/db-logger
More information about elminson/db-logger
Files in elminson/db-logger
Package db-logger
Short Description A powerful PHP package for logging SQL queries from Laravel applications, supporting both Eloquent and Query Builder instances, with flexible output options.
License MIT
Informations about the package db-logger
Database Query Logger
A powerful PHP package for logging SQL queries from Laravel applications, supporting both Eloquent and Query Builder instances, with flexible output options.
Installation
You can install the package via Composer:
Features
- [x] Log SQL queries from Eloquent or Query Builder instances
- [x] Log SQL queries to a file or the console
- [x] Log SQL queries with parameter bindings
- [x] Support for PDO statements
- [x] Configurable logging options
- [x] Timestamp-based log entries
- [x] Automatic directory creation for log files
- [x] Support for different parameter types (string, integer, boolean, null)
- [x] JSON log formatting
- [x] Log rotation (daily/weekly, max files)
Configuration
Environment Variables
Add these variables to your .env
file:
Configuration Options
The logger can be configured using environment variables (as shown above) or by passing an array to its constructor. If you publish the configuration file (config/db-logger.php
), you can manage these settings there.
Here are the available options:
enabled
(boolean): Enable or disable the logger completely. Default:false
.- Env:
DB_LOGGER_ENABLED
- Env:
console_output
(boolean): Enable or disable console output. Default:false
.- Env:
DB_LOGGER_CONSOLE_OUTPUT
- Env:
file_logging
(boolean): Enable or disable file logging. Default:false
.- Env:
DB_LOGGER_FILE_LOGGING
- Env:
log_file
(string): Path to the log file. Default:storage_path('logs/database-queries.log')
.- Env:
DB_LOGGER_FILE_PATH
- Env:
log_format
(string): Log format. Possible values:text
,json
. Default:text
.- Env:
DB_LOGGER_LOG_FORMAT
- Env:
log_rotation_enabled
(boolean): Enable or disable log rotation. Default:false
.- Env:
DB_LOGGER_ROTATION_ENABLED
- Env:
log_rotation_period
(string): Log rotation period. Possible values:daily
,weekly
. Default:daily
.- Env:
DB_LOGGER_ROTATION_PERIOD
- Env:
log_rotation_max_files
(integer): Maximum number of rotated log files to keep. Default:7
.- Env:
DB_LOGGER_ROTATION_MAX_FILES
- Env:
Publishing the Configuration File
If you want to customize the logger configuration, you can publish the config file to your Laravel project using the following Artisan command:
This will copy the configuration file to config/db-logger.php
in your Laravel application, where you can adjust the settings as needed.
Service Provider
Register the service provider in config/app.php
:
Usage
Basic Usage
PDO Statement Logging
Raw Query Logging
Configuration Methods
Testing
Run the tests with:
Run tests with coverage:
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
- Elminson De Oleo Baez
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
Log All Queries in Laravel
To log every SQL query executed by your Laravel application, add the following to your app/Providers/AppServiceProvider.php
:
Make sure your config/db-logger.php
and .env
are set up as described above. This will ensure all queries are logged according to your configuration.
All versions of db-logger with dependencies
illuminate/database Version ^8.0|^9.0|^10.0|^11.0|^12.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0|^12.0
laravel/framework Version ^8.0