PHPackages                             gdi/apilogger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. gdi/apilogger

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

gdi/apilogger
=============

A Laravel package for logging and debugging API requests.

2.0.0(1mo ago)07MITBladePHP ^8.1

Since Apr 12Pushed 1mo agoCompare

[ Source](https://github.com/devit-chea/apilogger)[ Packagist](https://packagist.org/packages/gdi/apilogger)[ RSS](/packages/gdi-apilogger/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

GDI API Logger
==============

[](#gdi-api-logger)

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.

---

Features
--------

[](#features)

- 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 `/apilogger` with 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

---

Installation
------------

[](#installation)

### 1. Place the package in your project

[](#1-place-the-package-in-your-project)

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/apilogger
```

### 2. Publish the config

[](#2-publish-the-config)

```
php artisan vendor:publish --tag=apilogger-config
```

This creates `config/apilogger.php`.

### 3. (Optional) Publish views

[](#3-optional-publish-views)

Only needed if you want to customise the dashboard UI:

```
php artisan vendor:publish --tag=apilogger-views
```

### 4. (DB driver only) Run the migration

[](#4-db-driver-only-run-the-migration)

```
php artisan vendor:publish --tag=apilogger-migrations
php artisan migrate
```

---

Configuration
-------------

[](#configuration)

`config/apilogger.php`:

KeyDefaultDescription`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 dashboardYou can also set these via `.env`:

```
APILOGGER_DRIVER=db
APILOGGER_LOG_RESPONSE=true
```

---

Usage
-----

[](#usage)

### Add middleware to routes

[](#add-middleware-to-routes)

Apply 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);
});
```

### Dashboard

[](#dashboard)

Visit `http://yourdomain.com/apilogger` to view the log dashboard.

You can filter by HTTP method, status code, and URL substring.

### Clear logs via Artisan

[](#clear-logs-via-artisan)

```
php artisan apilogger:clear
```

---

Securing the Dashboard
----------------------

[](#securing-the-dashboard)

In `config/apilogger.php`, add authentication middleware:

```
'route' => [
    'prefix'     => 'apilogger',
    'middleware' => ['web', 'auth'],   // or ['web', 'auth', 'can:view-logs']
],
```

---

Custom Driver
-------------

[](#custom-driver)

You can implement your own storage backend (e.g. Redis, MongoDB, S3):

### Step 1 — Create your driver class

[](#step-1--create-your-driver-class)

```
