AWS Developer Tools Blog

Wire Logging in the AWS SDK for PHP

One of the features of the AWS SDK for PHP that I often recommend to customers is the LogPlugin, that can be used to do wire logging. It is one of the many plugins included with Guzzle, which is the underlying HTTP library used by the SDK. Guzzle’s LogPlugin includes a default configuration that will output the content of the requests and responses sent over the wire to AWS. You can use it to help debug requests or just learn more about how the AWS APIs work.

Adding the LogPlugin to any client in the SDK is simple. The following shows how to set it up.

$logPlugin = GuzzlePluginLogLogPlugin::getDebugPlugin();
$client->addSubscriber($logPlugin);

The output generated by LogPlugin for a single request looks similar to the following text (this request was for executing an Amazon S3 ListBuckets operation).

# Request:
GET / HTTP/1.1
Host: s3.amazonaws.com
User-Agent: aws-sdk-php2/2.4.6 Guzzle/3.7.3 curl/7.25.0 PHP/5.3.27
Date: Fri, 27 Sep 2013 15:53:10 +0000
Authorization: AWS AKIAEXAMPLEEXAMPLE:eEXAMPLEEsREXAMPLEWEFo=

# Response:
HTTP/1.1 200 OK
x-amz-id-2: EXAMPLE4j/v8onDxyeuFaQFsNvN66EXAMPLE30KQLfq0T6sVcLxj
x-amz-request-id: 4F3EXAMPLEE14
Date: Fri, 27 Sep 2013 15:53:09 GMT
Content-Type: application/xml
Transfer-Encoding: chunked
Server: AmazonS3

<?xml version="1.0" encoding="UTF-8"?>
<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">[...]</ListAllMyBucketsResult>

This is the output generated using the default configuration. You can configure the LogPlugin to customize the behavior, format, and location of what is logged. It’s also possible to integrate with third-party logging libraries like Monolog. For more information, see the section about the wire logger in the AWS SDK for PHP User Guide.