topup / laralog
Log request & response including header, body etc...
v2.0.3
2021-06-01 10:47 UTC
Requires
- php: >=7.2
- ext-json: *
- illuminate/support: ^6.0
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
- Install the package via composer
composer require topup/laralog
Usage
- (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.
- Migrate using the command bellow:
php artisan migrate
-
Use middleware
topup-logger
to any route that need to debug -
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);
- 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=
- Enjoy