Download the PHP package garbetjie/http-request-logger without Composer

On this page you can find all versions of the php package garbetjie/http-request-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package http-request-logger

HTTP Request Logger

An HTTP request logging library that makes it simple to easy to implement the logging of all HTTP requests & responses.

Works with Laravel, Guzzle and PHP's SoapServer and SoapClient classes.

Table of contents

Introduction

It is often quite useful to be able to see all requests & responses generated by your application - especially whilst in development. This library makes it trivial to log all incoming & outgoing requests & responses using Monolog.

By default, all requests & responses are logged at the debug log level. Sensible defaults for logging context are used, and headers that may contain sensitive values (such as Cookie, Set-Cookie and Authorization) have their values obfuscated. Each request & corresponding response are linked together through a unique ID. This allows you to interrogate your logs to find the matching response for any given request.

Installation

Usage

Incoming requests in Laravel

Enabling request logging in Laravel is as simple as adding the middleware to the $middleware property on your App\Http\Kernel class. The example shown below is enough to ensure that all incoming requests & outgoing responses are logged in Laravel:

Take note: You should add the request logging middleware to your application's global middleware stack, and determine when logging should take place in a service provider. When added to a middleware group, any uncaught exceptions thrown will prevent the request & response from being logged.

See the Toggle enabled/disabled section for more information on this.

Incoming requests in PSR-15 compliant frameworks

If you are not using Laravel, but are making use of a framework that adheres to PSR-15, you'll need to be a little more explicit in creating the middleware. The example below makes use of the Slim framework as an example:

Incoming SOAP requests

Logging incoming SOAP requests is trivial. Instead of creating a new \SoapServer instance, simply create a new instance of \Garbetjie\RequestLogging\Http\SoapServer. You can use this new instance exactly the same as you would with an instance of \SoapServer. Example shown below:

Outgoing requests in Laravel

WHen using Laravel, you can simply type-hint either GuzzleHttp\ClientInterface or GuzzleHttp\Client wherever Laravel performs dependency injection. This package includes a service provider that automatically adds the middleware to a handler stack for you.

An example of using this type-hinting in a controller is shown below:

Outgoing requests through Guzzle

Outbound request logging happens through Guzzle middleware. In order to log outbound requests, simply add an instance of the OutgoingRequestLoggingMiddleware to your handler stack. Ideally, this should be the last middleware in your handler stack in order to ensure the logged representation of the request is as accurate as possible.

Outgoing SOAP requests

In order to log outbound SOAP requests, simply create your Guzzle client as if you be logging any other outgoing HTTP request, and pass this client instance to a new instance of Garbetjie\RequestLogging\Http\SoapClient. You can use this SOAP client instance just as if you were making use of a native SoapClient instance:

Customisation

All aspects of the request & response logging are customisable. This includes the ID used to link a request & response together, the log message, as well as the context logged with each request & response.

Logging context

By default, incoming & outgoing requests generate a context with a similar structure to below. Sensitive headers such as Authorization and Cookie have their values replaced with ***:

The context shown below indicates the default structure of the logging context for responses. Any Set-Cookie headers have their values stripped out and replaced with ***.

It is quite simple to customise the logging context that is generated:

If you'd like to simply extend off the context that is created by default, you can reuse the context extractors that are already available:

ID generation.

By default, the ID generation for linking requests & responses together makes use of endyjasmi/cuid to generate a full CUID.

This can be easily customised by providing a callable that simply returns a string containing the ID to use:

Toggling logging

By default, all requests & responses are logged. However, it is possible to toggle whether a request or response should be logged. Simply provide either a boolean value, or a callable that returns a boolean value indicating whether or not logging should be enabled for the given request:

Changelog

See CHANGELOG.md for the full changelog.


All versions of http-request-logger with dependencies

PHP Build Version
Package Version
Requires psr/http-message Version ^1.0
psr/log Version ^1.1
php Version ^7.3 || ^7.4 || ^8.0
psr/http-server-middleware Version ^1.0
endyjasmi/cuid Version ^2.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package garbetjie/http-request-logger contains the following files

Loading the files please wait ....