LogPlugin
in package
implements
EventSubscriberInterface
Plugin class that will add request and response logging to an HTTP request.
The log plugin uses a message formatter that allows custom messages via template variable substitution.
Tags
Interfaces, Classes and Traits
- EventSubscriberInterface
- An EventSubscriber knows itself what events it is interested in.
Table of Contents
- $formatter : MessageFormatter
- $logAdapter : LogAdapterInterface
- $wireBodies : bool
- __construct() : mixed
- getDebugPlugin() : self
- Get a log plugin that outputs full request, response, and curl error information to stderr
- getSubscribedEvents() : array<string|int, mixed>
- Returns an array of event names this subscriber wants to listen to.
- onCurlRead() : mixed
- Event triggered when curl data is read from a request
- onCurlWrite() : mixed
- Event triggered when curl data is written to a response
- onRequestBeforeSend() : mixed
- Called before a request is sent
- onRequestSent() : mixed
- Triggers the actual log write when a request completes
Properties
$formatter
protected
MessageFormatter
$formatter
Formatter used to format messages before logging
$logAdapter
protected
LogAdapterInterface
$logAdapter
Adapter responsible for writing log data
$wireBodies
protected
bool
$wireBodies
Whether or not to wire request and response bodies
Methods
__construct()
public
__construct(LogAdapterInterface $logAdapter[, string|MessageFormatter $formatter = null ][, bool $wireBodies = false ]) : mixed
Parameters
- $logAdapter : LogAdapterInterface
-
Adapter object used to log message
- $formatter : string|MessageFormatter = null
-
Formatter used to format log messages or the formatter template
- $wireBodies : bool = false
-
Set to true to track request and response bodies using a temporary buffer if the bodies are not repeatable.
Return values
mixed —getDebugPlugin()
Get a log plugin that outputs full request, response, and curl error information to stderr
public
static getDebugPlugin([bool $wireBodies = true ][, resource $stream = null ]) : self
Parameters
- $wireBodies : bool = true
-
Set to false to disable request/response body output when they use are not repeatable
- $stream : resource = null
-
Stream to write to when logging. Defaults to STDERR when it is available
Return values
self —getSubscribedEvents()
Returns an array of event names this subscriber wants to listen to.
public
static getSubscribedEvents() : array<string|int, mixed>
The array keys are event names and the value can be:
- The method name to call (priority defaults to 0)
- An array composed of the method name to call and the priority
- An array of arrays composed of the method names to call and respective priorities, or 0 if unset
For instance:
- ['eventName' => 'methodName']
- ['eventName' => ['methodName', $priority]]
- ['eventName' => [['methodName1', $priority], ['methodName2']]]
The code must not depend on runtime state as it will only be called at compile time. All logic depending on runtime state must be put into the individual methods handling the events.
Return values
array<string|int, mixed> —The event names to listen to
onCurlRead()
Event triggered when curl data is read from a request
public
onCurlRead(Event $event) : mixed
Parameters
- $event : Event
Return values
mixed —onCurlWrite()
Event triggered when curl data is written to a response
public
onCurlWrite(Event $event) : mixed
Parameters
- $event : Event
Return values
mixed —onRequestBeforeSend()
Called before a request is sent
public
onRequestBeforeSend(Event $event) : mixed
Parameters
- $event : Event
Return values
mixed —onRequestSent()
Triggers the actual log write when a request completes
public
onRequestSent(Event $event) : mixed
Parameters
- $event : Event