AWS PHP SDK logging using Guzzle


Recently I’ve been working on AWS PHP SDK. I found out that there is a simple code snippet to enable wire logging in the API

use Guzzle\Plugin\Log\LogPlugin;

// Create an Amazon S3 client
$s3Client = S3Client::factory();

// Add a debug log plugin
$s3Client->addSubscriber(LogPlugin::getDebugPlugin());

However according to FAQs on the AWS docs site, we have to create our own plugin for logging in a file. I had a look at the code and found that you just have to provide the 2nd parameter to getDebugPlugin function and it wil start logging in the file

// Create an Amazon S3 client
$s3Client = S3Client::factory();

$logPlugin = LogPlugin::getDebugPlugin(TRUE,
  //Don't provide this parameter to show the log in PHP output
  fopen(APPPATH . 'logs/wire.log', 'a')
 );
$client->addSubscriber($logPlugin);

Later if you want to stop the logging you have to use the following snippet.

//Remove this log plugin to the client
 $client->getEventDispatcher()->removeSubscriber($logPlugin);
Advertisements

I am a web developer working @ Gaditek

Tagged with: , , , ,
Posted in Amazon, Programming & Development

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

About me
A geek trying to make world a better place to live.

I mostly work on Web Technologies like PHP, Javascript. I also work on Python, GAE and Netsuite Customization. Currently working @ Cloudways

Profile Links Linkedin | Github | Stackoverflow
Subscribe to this blog
%d bloggers like this: