Small laravel package for viewing api logs which can be used in debugging.

Overview

API Logger

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

screenshot

Installation

  1. Install the package via composer
composer require awt/apilogger @dev

Usage

  1. Laravel 5.5 and higher uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider. If you use a lower version of Laravel you must register it in your app.php file:
AWT\Providers\ApiLogServiceProvider::class
  1. Publish the config file with:
php artisan vendor:publish --tag=config --provider="AWT\Providers\ApiLogServiceProvider"

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 can also configure which fields should not be logged like passwords, secrets, etc.

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

php artisan migrate
  1. 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");
});
  1. Dashboard can be accessible via yourdomain.com/apilogs

Clear the logs

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

php artisan apilog:clear

Implement your own log driver

  1. Your driver class must implement ApiLoggerInterface for saving, retrieving and deleting the logs.
  2. Your driver class may extends AbstractLogger class which provide helpful methods such as logData and mapArrayToModel.
  3. Substitude in your new class name instead of db or file as the driver. eg: \App\Apilogs\CustomLogger::class

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.

Comments
  • [Laravel 6.0.4] Auto-Discovery and config Publish didn't work

    [Laravel 6.0.4] Auto-Discovery and config Publish didn't work

    Hi,

    First of all, thank you for your work.

    I am using Laravel version 6.0.4 and composer version 1.9.0.

    I followed the README and add apilogger to composer. But the apilogger service provider didn't show on package discovery. That's my first issue.

    I executed the command to publish the vendor. The apilog.php file has not been added to the config Laravel's folder. That's my second issue. It might be link to the first issue.

    So i add manualy the config file and the apilogger service provider and it works.

    • Is there something i am missing ?
    • Is related to Laravel 6.0 (i didn't test with oldest version) ? Other packages didn't have the issue.

    I hope it will help.

    bug 
    opened by alijem 8
  • Laravel 6.X | Undefined Offset Bug?

    Laravel 6.X | Undefined Offset Bug?

    [
        {
            "id": 1,
            "testCamelCase": "Camel Case",
            "testSnakeCase": null,
            "test_snake_case": "Snake Case"
        }
    ]
    
    {
        "message": "Undefined offset: 1",
        "exception": "ErrorException",
        "file": "C:\\laragon\\webroots\\current\\laravel-six\\vendor\\awt\\apilogger\\src\\AbstractLogger.php",
        "line": 48,
        "trace": [
            {
                "file": "C:\\laragon\\webroots\\current\\laravel-six\\vendor\\awt\\apilogger\\src\\AbstractLogger.php",
                "line": 48,
                "function": "handleError",
                "class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
                "type": "->"
            },
            {
                "file": "C:\\laragon\\webroots\\current\\laravel-six\\vendor\\awt\\apilogger\\src\\DBLogger.php",
                "line": 33,
                "function": "logData",
                "class": "AWT\\AbstractLogger",
                "type": "->"
            },
            {
                "file": "C:\\laragon\\webroots\\current\\laravel-six\\vendor\\awt\\apilogger\\src\\Http\\Middleware\\ApiLogger.php",
                "line": 30,
                "function": "saveLogs",
                "class": "AWT\\DBLogger",
                "type": "->"
            },
            {
                "file": "C:\\laragon\\webroots\\current\\laravel-six\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
                "line": 218,
                "function": "terminate",
                "class": "AWT\\Http\\Middleware\\ApiLogger",
                "type": "->"
            },
            {
                "file": "C:\\laragon\\webroots\\current\\laravel-six\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
                "line": 189,
                "function": "terminateMiddleware",
                "class": "Illuminate\\Foundation\\Http\\Kernel",
                "type": "->"
            },
            {
                "file": "C:\\laragon\\webroots\\current\\laravel-six\\public\\index.php",
                "line": 60,
                "function": "terminate",
                "class": "Illuminate\\Foundation\\Http\\Kernel",
                "type": "->"
            }
        ]
    }```
    bug 
    opened by lloy0076 5
  • Error while installing this package

    Error while installing this package

    Hi, I tired installing the package but I got following error.

    Class AWT\Http\Exceptions\InvalidApiLogDriverException located in D:/laragon/www/eazy-customs-api/vendor/awt/apilogger/src\Exceptions\InvalidApiLogDriverException.php does not comply with psr-4 autoloading standard. Skipping.
    > Illuminate\Foundation\ComposerScripts::postAutoloadDump
    > @php artisan package:discover --ansi
    
    In ApiLogServiceProvider.php line 59:
    
      Class 'AWT\Http\Exceptions\InvalidApiLogDriverException' not found
    
    
    Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
    
    Installation failed, reverting ./composer.json and ./composer.lock to their original content.
    
    opened by IAmShafqatAli 2
  • Provide some basic filtering in `apilogs` route

    Provide some basic filtering in `apilogs` route

    I am not so much making an issue here, but rather opening some dialog about enhancing the apilogs route to include some basic filtering or query functions.

    I am thinking maybe allowing some sort of search functionality, or filter request type, etc. This apilogs route could get very big and hard to navigate in a hurry.

    Perhaps at a minimum, maybe show a drop-down to select the desired day in the file logger is being used (which it is in my case). In my local usage, I was trying to track down some entries for the last couple of days of use, but it was a "massive" list already.

    I suppose I could use the DB logger and navigate using TablePlus or SequelPro, but I really don't want to log to the database if I can avoid it, much rather use FileLogger

    If anybody wants to chime in here, I am all ears

    enhancement 
    opened by mikeerickson 2
  • Restore Code Removed by PR #8.

    Restore Code Removed by PR #8.

    I took out:

    
            $endTime = microtime(true);
    
            $implode_models = $this->models;
    
            array_walk($implode_models, function(&$value, $key) {
                $value = "{$key} ({$value})";
            });
    

    By accident.

    See PR #10.

    opened by lloy0076 2
  • Issue 8 - Undefined Offset Bug (for Single Action Controllers/Closures).

    Issue 8 - Undefined Offset Bug (for Single Action Controllers/Closures).

    If given a single action controller of closure, the previous code would unceremoniously crash with an "Undefined offset: 1" error (see Issue #8).

    This handles the $currentRouteAction differently in that:

    1. If we can split it by @ we do and it will behave as before;
    2. If we cannot, we'll check if $currentRouteAction is a string and if, and only if it is, we'll set the $controller to empty and the current action as the value of $currentAction - this is not necessarily ideal but it is better than crashing;
    3. If it's something else entirely we will use json_encode and set the current action to be that value.

    We could probably tell if $currentAction is a closure and/or a single action controller BUT the main goal of this commit is to stop crashing.

    I have tested it on Laravel 6.X.

    Resolved #8.

    opened by lloy0076 2
  • Log file date format

    Log file date format

    I am looking for a way to customize the date format in API log files? I checked the apilog.php file but doesn't exist.

    Personally, I would like to have same format used by Laravel logs

    Eg.

    apilogger-2019-08-08.log

    or, better yet in my desired format

    api-2019-08-08.log

    Possible config entry

    <?php
    
    return [
        //currently supported drivers are 'db' and 'file'
        "driver" => "file",
        "filename" => "api-yyyy-mm-dd.log"
    ];
    

    Thinking of a quick change to FileLogger.php:61

       $filename = 'api-'.date('Y-m-d') . '.log';
    

    If you are interested, I would be happy to make a PR for this (unless you already have plans for this capability).

    opened by mikeerickson 2
  • Please Downgrade The PHP Version

    Please Downgrade The PHP Version

    Thank you for updating the log interface. But, may you downgrade the minimum php version ?

    Because many of my project using this lib on for laravel 5.5 and laravel 6.0 that using php 7.2 After you new commit, it makes this lib only available with minimum php 8 that makes me can't install it on the old version of laravel. The minimum php 8 force the developer to upgrade minimum laravel 8.0.

    Please, download the php version. Thank you so much

    opened by jacow 1
  • Major updates

    Major updates

    Better GUI Full with Move information on top Payload display with formating

    Add middelware to route in config + url changes PSR-4 compatibility

    Fix migrations running even if driver was file

    Remove vendor folder Update requirement composer Add payload raw New UI with tab Add option to save the response Add option to auto-detect response type Add blacklist headers Fix databases structure Fix migration running even in file mode Typed parameters for better controls Rewrite log file format, old one no longer compatible Add pagination for Database driver

    opened by dansleboby 1
  • User context is missing

    User context is missing

    Hi, it seems to be a great package. However it would be nice to see what user accesed some particular endpoint. In my case - user_id, username, email, company_id (from JWT payload) would be required.

    opened by Sakvojage 1
  • Continued support

    Continued support

    I am curious if you have plans for continued support and maintenance. If not, I would very much be interested in becoming maintainer? Let me know if you are interested.

    Mike Erickson [email protected]

    opened by mikeerickson 0
  • ApiLoggerInterface Issue

    ApiLoggerInterface Issue

    Hello,

    Laravel version: "laravel/framework": "^6.18.35" I'm using the below 2 packages at the same time:

    "awt/apilogger": "dev-master"
    "tightenco/ziggy": "^1.0"
    

    I've added @routes to some blade files which will be used to get all routes in the javascript files. Now I wanted to add some other packages and after installing/removing other packages I'm getting the error in pages where I've added @routes

    I tried removing, installing, and updating the package. Also, checked some solutions and tried this one (Stackoverflow).

    The error screenshot is attached. Can I get the solution for the same?

    Error

    opened by kuldeepBacancy 0
  • Deprecation Notice on

    Deprecation Notice on "composer dumpautoload"

    Deprecation Notice: Class AWT\Http\Exceptions\InvalidApiLogDriverException located in ./vendor/awt/apilogger/src/Exceptions/InvalidApiLogDriverException.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/local/Cellar/composer/1.10.10/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201

    opened by jacow 1
  • ErrorException

    ErrorException

    ErrorException
    Declaration of AWT\Http\Controllers\ApiLogController::index(AWT\Contracts\ApiLoggerInterface $logger) should be compatible with App\Http\Controllers\Controller::index(Illuminate\Http\Request $request)
    
    opened by vasyakrg 2
  • HOw to protected api logger

    HOw to protected api logger

    Hi i am new in laravel can you pls guide me how to make password protected api logger

    i follow all given command which given by you.

    thanks in advance.

    opened by rg0492 2
Owner
awt
The difference between kung fu panda and me is that I do not know any kung fu.
awt
Keep your laravel logs small and tidy.

Logs can get quite out of hand. This package helps save server space and keep your Laravel log files small.

Accent Interactive 73 Nov 14, 2022
Small tool that extracts witness data from Helium miner logs.

Helium Miner Logs Analyzer Small tool that extracts witness data from Helium miner logs. It currently works for the Pisces 100 and miner version miner

Iñigo Flores 42 Dec 11, 2022
Logs which process created or modified a record

It is sometimes very useful to know which process created or modified a particular record in your database. This package provides a trait to add to your Laravel models which automatically logs that for you.

ORIS Intelligence 98 Dec 4, 2022
Log Laravel application request and response with a unique ID for easy debugging

Flexible and extendable logging of Laravel application request and responses Zero configuration logging of Requests and Responses to database or custo

Bilfeldt 37 Nov 6, 2022
Sends your logs to files, sockets, inboxes, databases and various web services

Monolog - Logging for PHP Monolog sends your logs to files, sockets, inboxes, databases and various web services. See the complete list of handlers be

Jordi Boggiano 20.1k Jan 8, 2023
Amazon Web Services CloudWatch Logs Handler for Monolog library

AWS CloudWatch Logs Handler for Monolog Handler for PHP logging library Monolog for sending log entries to AWS CloudWatch Logs service. Before using t

Maksym Leonov 377 Dec 16, 2022
Paste, share and analyse Minecraft server logs

mclo.gs Paste, share & analyse your Minecraft server logs About The project mclo.gs was created in 2017 by the Aternos team after more than 4 years of

Aternos 99 Jan 3, 2023
Capture and monitor detailed error logs with nice dashboard and UI

Capture and monitor detailed error logs with nice dashboard and UI Requirements Check Laravel 6 requirements Check Laravel 7 requirements Installation

Bugphix 107 Dec 12, 2022
Clear all your logs in [linux/windows] servers 🛡️

Log-killer Log Killer is tool for [Linux/Windows] Servers This tool will delete all your logs just download the tool and run it on the server if your

Rizer 281 Nov 24, 2022
Allows you to process logs using any PSR-3 compatible logger such as Monolog

Yii 2 PSR Log Target Allows you to process logs using any PSR-3 compatible logger such as Monolog

Alexander Makarov 67 Dec 14, 2022
Sends your logs to files, sockets, inboxes, databases and various web services

Monolog - Logging for PHP ⚠ This is the documentation for Monolog 3.x, if you are using older releases see the documentation for Monolog 2.x or Monolo

Jordi Boggiano 20.1k Jan 7, 2023
This package is for centralized logging of multiple Laravel application into one connection.

Laralogs This package is for centralized logging of multiple Laravel application into one connection. Installation You can install the package via com

Remon 4 Apr 26, 2022
Simple PHP Logger. Composer package

Basic PHP Logger ?? Simple logger. Composer package.

null 1 Jan 28, 2022
AcLog is a simple, zero-dependency PHP package to log activity to files

AcLog is a simple, zero-dependency PHP package to log activity to files. This is not meant for logging errors, this is can be used for logging c

null 2 Sep 9, 2022
High-performance API performing logging for PHP applications into files or SysLog

Logging API Table of contents: About Configuration Binding Points Logging Installation Unit Tests Reference Guide Specifications How Are Log Lines For

Lucian Gabriel Popescu 0 Jan 9, 2022
Laravel logger is an activity event logger for your Laravel or Lumen application

Laravel logger is an activity event logger for your Laravel or Lumen application. It comes out the box with ready to use with dashboard to view your activity. Laravel logger can be added as a middleware or called through a trait. Easily have an Activity Log. This package is easily configurable and customizable. Supports Laravel 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 6, and 7+

Jeremy Kenedy 475 Dec 22, 2022
A simple database logger for all outgoing emails sent by Laravel website.

Laravel Email Database Log A simple database logger for all outgoing emails sent by Laravel website.

Shvets Group 136 Jan 4, 2023
A simple and beautiful laravel log reader

Laravel Log Reader A simple and beautiful laravel log reader Documentation Get full documentation of Laravel Log Reader Other Packages Laravel H - A h

Md.Harun-Ur-Rashid 356 Dec 30, 2022
📑 Laravel HTTP Logger

Logging incoming HTTP requests

The Dragon Code 28 Nov 29, 2022