Laravel – API Logger Package

This is a small package that can help in debugging API logs. It can log request method, URL, duration, request payload, which models are retrieved, controller and method.

Here is the Dashboard comes with the package.

Dashboard

How to install API logger package :

composer require awt/apilogger @dev

How to use API logger package :

1. Register it in your app.php file

AWT\Providers\ApiLogServiceProvider::class

2.Publish the config file with:

php artisan vendor:publish --tag=config

The config file is called apilogs.php. Currently supported drivers are db and file

By default, the logger will use file to log the data. But if you want to use Database for logging, migrate table by using

You dont need to migrate if you are just using file driver

php artisan migrate

3. Add middleware named apilogger to the route or controller you want to log data

//in route.php or web.php
Route::middleware('apilogger')->post('/test',function(){
    return response()->json("test");
});

4. Dashboard can be accessible via yourdomain.com/apilogs

Clear the logs

You can permanently clear the logs by using the following command.

php artisan apilog:clear

That’s it 🙂

This package is created by  @aungwinthant 

Github Link

Leave a Reply

Your email address will not be published. Required fields are marked *