A self-maintained Laravel package for logging, inspecting, and debugging API requests. Supports both file and database drivers, a built-in dashboard, and is fully extensible with custom drivers.
- Logs: HTTP method, URL, status code, duration (ms), request payload, response body, controller, action method, Eloquent models retrieved, IP, and authenticated user
- Two storage drivers out of the box: file and db
- Pluggable custom driver interface
- Dashboard UI at
/apiloggerwith filtering, pagination, and detail view - Hidden fields (passwords, tokens, etc.) automatically masked
- Artisan command to clear logs
- Zero external JS/CSS dependencies — dashboard is self-contained
For an internal package, add it to your project's packages/ directory and register it in composer.json:
"repositories": [
{
"type": "path",
"url": "./packages/apilogger"
}
],
"require": {
"gdi/apilogger": "*"
}Then run:
composer require gdi/apiloggerphp artisan vendor:publish --tag=apilogger-configThis creates config/apilogger.php.
Only needed if you want to customise the dashboard UI:
php artisan vendor:publish --tag=apilogger-viewsphp artisan vendor:publish --tag=apilogger-migrations
php artisan migrateconfig/apilogger.php:
| Key | Default | Description |
|---|---|---|
driver |
file |
Storage driver: file, db, or a custom class name |
log_file |
logs/apilogger.log |
File path (relative to storage/) for the file driver |
max_entries |
1000 |
Max entries kept by file driver (0 = unlimited) |
hidden_fields |
[password, token, ...] |
Request fields replaced with *** |
log_response |
true |
Whether to capture response body |
max_response_length |
5000 |
Characters to store per response (0 = unlimited) |
route.prefix |
apilogger |
Dashboard URL prefix |
route.middleware |
['web'] |
Middleware applied to dashboard routes |
per_page |
20 |
Entries per page on the dashboard |
You can also set these via .env:
APILOGGER_DRIVER=db
APILOGGER_LOG_RESPONSE=trueApply the apilogger middleware to any route or route group you want to log:
// Single route
Route::middleware('apilogger')->post('/api/orders', [OrderController::class, 'store']);
// Route group
Route::middleware(['auth:sanctum', 'apilogger'])->group(function () {
Route::apiResource('products', ProductController::class);
});Visit http://yourdomain.com/apilogger to view the log dashboard.
You can filter by HTTP method, status code, and URL substring.
php artisan apilogger:clearIn config/apilogger.php, add authentication middleware:
'route' => [
'prefix' => 'apilogger',
'middleware' => ['web', 'auth'], // or ['web', 'auth', 'can:view-logs']
],You can implement your own storage backend (e.g. Redis, MongoDB, S3):
<?php
namespace App\ApiLogger;
use GDI\ApiLogger\Drivers\AbstractLogger;
class RedisLogger extends AbstractLogger
{
public function save(array $data): void
{
// push $data to Redis
}
public function all(int $perPage = 20, array $filters = []): mixed
{
// return paginated results
}
public function find(mixed $id): ?array
{
// return a single entry or null
}
public function clear(): void
{
// delete all entries
}
}Your class:
- Must implement
GDI\ApiLogger\Contracts\ApiLoggerInterface - May extend
GDI\ApiLogger\Drivers\AbstractLoggerto inheritbuildLogData()andfilterHidden()helpers
In config/apilogger.php:
'driver' => \App\ApiLogger\RedisLogger::class,packages/apilogger/
├── composer.json
├── config/
│ └── apilogger.php
├── database/
│ └── migrations/
│ └── 2024_01_01_000000_create_api_logs_table.php
├── resources/
│ └── views/
│ ├── layouts/
│ │ └── app.blade.php
│ ├── index.blade.php
│ └── show.blade.php
├── routes/
│ └── web.php
└── src/
├── Console/
│ └── ClearLogsCommand.php
├── Contracts/
│ └── ApiLoggerInterface.php
├── Drivers/
│ ├── AbstractLogger.php
│ ├── DatabaseLogger.php
│ └── FileLogger.php
├── Http/
│ ├── Controllers/
│ │ └── ApiLoggerController.php
│ └── Middleware/
│ └── ApiLoggersMiddleware.php
├── Models/
│ └── ApiLogger.php
└── Providers/
└── ApiLoggerServiceProvider.php
MIT