topup/laralog

Log request & response including header, body etc...

v2.0.3 2021-06-01 10:47 UTC

This package is auto-updated.

Last update: 2025-07-18 11:36:46 UTC


README

A tiny package to debug request & response. It will log request & response header, user IP, time took to process the request & sending response. If a logged in user make the request it will log the user ID too.

Installation

  1. Install the package via composer
composer require topup/laralog

Usage

  1. (Optional) Set environment variables to use your own custom layout
TOPUP_LOGGER_LAYOUT="topup-logger::app"
TOPUP_LOGGER_CONTENT_SECTION=content

Both env value will fall back to package default value.

  1. Migrate using the command bellow:
php artisan migrate
  1. Use middleware topup-logger to any route that need to debug

  2. Log outbound request with guzzle http

use GuzzleHttp\Client;
use Topup\Logger\Http\Middleware\TopupGuzzleLoggerMiddleware;

$logger = new TopupGuzzleLoggerMiddleware();
$handlerStack = HandlerStack::create();
$handlerStack->setHandler(new CurlHandler());
$handlerStack->push($logger->log());

$client = new Client(['handler' => $handlerStack]);

Or

$history = Middleware::history($this->_guzzleReqResContainer);
$this->_handlerStack = HandlerStack::create();
$this->_handlerStack->push($history);

$client = new Client(['handler' => $handlerStack]);

(new LoggerController())->saveLog($this->_guzzleReqResContainer);
  1. Apply middlewares for package routes via .env
TOPUP_LOGGER_ROUTE_MIDDLEWARE=web,auth,admin

Separate multiple middlewares with a comma(,) i.e. auth,admin

Default will fallback to web

Empty is allowed if you intend not to use any middleware

TOPUP_LOGGER_ROUTE_MIDDLEWARE=
  1. Enjoy