Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Guzzle Log Middleware Laravel Package

rtheunissen/guzzle-log-middleware

Lightweight Guzzle middleware for logging HTTP requests and responses. Capture method, URL, headers, body, status and timing, and route logs through PSR-3/Monolog with configurable formats, levels, and filtering—ideal for debugging and auditing API traffic.

View on GitHub
Deep Wiki
Context7

Guzzle 6/7 middleware to log requests and responses

Author License Latest Version Build Status Scrutinizer Scrutinizer Coverage

Installation

composer require rtheunissen/guzzle-log-middleware

Usage

use Concat\Http\Middleware\Logger;

Logger

You can use either a PSR-3 logger (such as Monolog) or a callable that accepts a log level, message, and context as an array.

$middleware = new Logger($logger);

or

$middleware = new Logger(function ($level, $message, array $context) {
    // Log the message
});

Log level

You can set a log level as a string or a callable that accepts a response. If the response is not set, it can be assumed that it's a request-only log, or that the request has been rejected. If the log level is not set, the default log level will be used which is LogLevel::NOTICE for status codes >= 400, or LogLevel::INFO otherwise.

use Psr\Log\LogLevel;

$middleware->setLogLevel(LogLevel::DEBUG);

or

$middleware->setLogLevel(function ($response) {
    // Return log level
});

Formatter

You can set a message formatter as a MessageFormatter or a callable that accepts a request, response, as well as a reason when a request has been rejected.

$middleware->setFormatter($formatter);

or

$middleware->setFormatter(function ($request, $response, $reason) {
    // Return log message
});

or

$middleware = new Logger($logger, $formatter);

Request logging

A request will only be logged when its response is received. You can enable request logging by using $middleware->setRequestLoggingEnabled(true), which will log a request when it is requested, as well as its response when it is received. Any $response references will be null in the case where only the request exists.

Middleware

This package is designed to function as Guzzle 6/7 Middleware.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky