Laravel-Flashlight is a minimal package to log incoming requests to your application; it is highly customizable and easy to install.
Take these steps to install Flashlight.
Install the package from Composer.
composer require hesamrad/laravel-flashlight
Publish congifuration file.
php artisan vendor:publish --provider="HesamRad\Flashlight\FlashlightServiceProvider" --tag="flashlight-config"
Publish migration file. (Only if you want to store logs inside your database.)
php artisan vendor:publish --provider="HesamRad\Flashlight\FlashlightServiceProvider" --tag="flashlight-migration"
Apply middleware on routes.
Route::middleware('flashlight')->group(function () {
Route::get('/', [SomeController::class, 'index']);
});
And you're done!
Now every request that goes through Flashlight will be logged to be monitored later.
Note that all Flashlight logs are stored in flashlight.log
file under storage/logs
.
If you wish to turn Flashlight on/off for a short time, you can do so by editing enabled
key inside flashlight.php
config file under App/config
.
'enabled' => true
Note that by default Flashlight is enabled.
There are a number of drivers you can choose to log the incoming requests to your application. You could choose file
or database
which will respectively store log records in a local file or a database table. You can change the driver by editing driver
key inside flashlight.php
config file under App/config
. (This value corresponds to an existing key inside drivers
array.)
'driver' => 'file'
Note that Flashlight uses file
driver as its default driver.
If you wish to customize HTTP methods to log, you can do so by editing excluded_methods
array inside flashlight.php
config file under App/config
.
For example:
'excluded_methods' => [
'put',
]
By doing this, all PUT
requests are ignored by Flashlight.
Note that by default all HTTP method are logged by Flashlight.
If you wish to log request headers, you can do so by editing log_headers
key inside flashlight.php
config file under App/config
.
'log_headers' => true
Note that by default request headers are logged by Flashlight.
If you wish to log request body, you can do so by editing log_body
key inside flashlight.php
config file under App/config
.
'log_body' => true
Note that by default request body is logged by Flashlight.
If you wish to customize request parameters to log, you can do so by editing excluded_parameters
array inside flashlight.php
config file under App/config
.
For example:
'excluded_parameters' => [
'password',
'password_confirmation',
]
By doing this, all specified parameters are ignored by Flashlight.
Note that by default password
and password_confirmation
parameters are ignored by Flashlight.
If you wish to customize URIs to log, you can do so by editing excluded_uris
array inside flashlight.php
config file under App/config
.
For example:
'excluded_uris' => [
'admins*',
]
By doing this, all requests under /admins
are ignored by Flashlight.
Note that by default all requests are logged by Flashlight.
No problem! Flashlight comes with a prune command to remove old logs to maintain a lighter table inside your storage.
All you have to do, is to run php artisan flashlight:prune
command to make this happen.
Note that by default value is 30 days; and Flashlight will remove anything older than that; so if you want to change this value to your liking, you can do so by editing prune_period
array inside flashlight.php
config file under App/config
.