elminson / db-logger
This is my package db-logger
Fund package maintenance!
elminson
Requires
- php: ^8.1
- illuminate/database: ^9.0
- illuminate/support: ^9.0
Requires (Dev)
- laravel/pint: ^1.0
- pestphp/pest: ^2.0
- spatie/ray: ^1.28
README
A simple PHP package to log SQL queries from Eloquent or Query Builder instances.
Installation
You can install the package via Composer:
composer require elminson/database-query-logger
This is where your description should go. Try and limit it to a paragraph or two. Consider adding a small example.
Features
- Log SQL queries from Eloquent or Query Builder instances
- Log SQL queries to a file or the console
- Log SQL queries with or without bindings
- Log SQL queries with or without execution time
- Log SQL queries with or without the backtrace
- Log SQL queries with or without the caller
- Log SQL queries with or without the memory usage
- Log SQL queries with or without the memory peak usage
Usage
Logging a Query
To log a query, you can use the log_query helper function:
use Illuminate\Database\Capsule\Manager as DB; // Set up the database connection $db = new DB; $db->addConnection([ 'driver' => 'sqlite', 'database' => ':memory:', ]); $db->setAsGlobal(); $db->bootEloquent(); // Create a test table DB::schema()->create('users', function ($table) { $table->increments('id'); $table->string('email'); }); // Insert a test record DB::table('users')->insert([ 'email' => 'example@example.com', ]); $query = DB::table('users')->where('email', 'example@example.com'); // Log the query log_query($query, true, true);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.