2017 © Pedro Peláez
 

library guzzle-log-middleware

Guzzle middleware to log requests and responses

image

rtheunissen/guzzle-log-middleware

Guzzle middleware to log requests and responses

  • Monday, November 6, 2017
  • by rtheunissen
  • Repository
  • 1 Watchers
  • 39 Stars
  • 398,025 Installations
  • PHP
  • 12 Dependents
  • 1 Suggesters
  • 6 Forks
  • 1 Open issues
  • 10 Versions
  • 10 % Grown

The README.md

Guzzle 6/7 middleware to log requests and responses

Author License Latest Version Build Status Scrutinizer Scrutinizer Coverage, (*1)

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., (*2)

$middleware = new Logger($logger);

or, (*3)

$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., (*4)

use Psr\Log\LogLevel;

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

or, (*5)

$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., (*6)

$middleware->setFormatter($formatter);

or, (*7)

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

or, (*8)

$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., (*9)

Middleware

This package is designed to function as Guzzle 6/7 Middleware., (*10)

The Versions

06/11 2017

dev-master

9999999-dev

Guzzle middleware to log requests and responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

middleware log http psr7 guzzle

06/11 2017

v0.4.1

0.4.1.0

Guzzle middleware to log requests and responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

middleware log http psr7 guzzle

16/06 2015

v0.4.0

0.4.0.0

Guzzle middleware to log requests and responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

middleware log http psr7 guzzle

14/06 2015

v0.3.0

0.3.0.0

Guzzle middleware to log requests and responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

14/06 2015

v0.2.3

0.2.3.0

Guzzle middleware to log requests and responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

13/06 2015

v0.2.2

0.2.2.0

Guzzle middleware to log requests and responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

13/06 2015

v0.2.1

0.2.1.0

Guzzle middleware to log requests and responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

13/06 2015

v0.2.0

0.2.0.0

Guzzle middleware to log requests and responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

13/06 2015

v0.1.0

0.1.0.0

Guzzle middleware to log requests and responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen

12/06 2015

v0.0.1

0.0.1.0

Guzzle middleware to log requests and responses

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rudi Theunissen