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.
- Install the package via composer
composer require topup/laralog
- (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