Download the PHP package web-chefs/db-lojack without Composer
On this page you can find all versions of the php package web-chefs/db-lojack. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package db-lojack
DB-LoJack
Laravel database query logger and debugger that support basic argument replacement.
Features
- Basic Query binding replacement
- Middleware and Listener handlers
- Security information hiding in production and staging environments
- Request query count logging
- Logs web and console queries
- DBLog facade for easy developer query debugging
- Configurable
- Default text logger support log file rotating without any dependencies on other packages
Versions
Confirmed to be working:
- Laravel 5.3 on PHP 5.6
- Laravel 5.4 on PHP 5.6, 7.0
- Laravel 5.5 on PHP 7.0, 7.1
- Laravel 5.6 on PHP 7.1
Install
Via Composer
Add Service Provider to config/app.php
Optionall add the DB LoJack Facade
Handlers
There are two handlers available each different pros and cons.
Middleware (Default)
Uses Laravel HTTP kernel middleware to enable database query logging and at the end of the request logs all queries as single block.
Pros
- Logs all queries as single block allowing you to trace queries to a specific request
- Logs query time in milliseconds for each query
Cons
- Does not work for console commands (See Event Listener)
- If large number of queries are executed in a request the tracking of the query data by Laravel can consume a large amount of memory, Middleware method should not be used for long running processes or requests
- If not the first middleware some queries can be missed, should be setup to be above any middleware that make database calls
Setup
Configure handler to middleware
.
Add Middleware to App\Http\Kernel
Event Listener
Uses a Laravel Event listener database events. Regardless of configurations this method is used in console / artisan applications.
Pros
- Handles queries one at a time so is more memory efficient
- Logs all queries regardless of setup
Cons
- Does not log queries times consistently, often not provided by laravel
- Multiple queries for one request are logged as separately making it more difficult to trace back to a specific request
Setup
Configure handler to listener
.
Developer Usage (Facade)
Logs
Query Logs
Query logs will log individual queries to a text file rotated daily.
EG: storage/logs/db/db_query.console.2018-06-06.log
.
Performance Watchdog Logs
A PerformanceWatchdog
class will collect statistics and queries and if a metric threshold is equaled or exceeded it will write a log.
Summary Log:
Records a single line per a request of the totals.
Detailed Log:
A log of each query run including with counters for each query and a mini stacktrace for each unique path to that query.
Configurations
To customize the configuration publish the config/db-lojack.php
.
Default Config
Security & Information Leaking
It is generally a very bad idea to log full database queries in production with actual parameters / bindings as this will end up logging sensitive information like usernames, passwords and sessions ids to a generally low security location in the form of application logs.
For this reason if the Laravel environment is set to production
or staging
queries will be logged but without bindings being replace and queries will be left with ?
placeholders.
Contributing
All code submissions will only be evaluated and accepted as pull-requests. If you have any questions or find any bugs please feel free to open an issue.
Credits
- All Contributors
License
The MIT License (MIT). Please see License File for more information.