google/google-api-php-client — pull request #394 by whatthejeff (2014-11-16 21:57:54+00:00)
Title: Add a PSR-3 style logging system that should be compatible with PHP 5.2+

More information on PSR-3 here: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md

This logging system roughly complies with the requirements for PSR-3, but does
not actually extend/implement/reuse any of the PSR namespaces, classes or
interfaces. This decision was made in an effort to maintain compatibility with
PHP 5.2+ and to be consistent with the current style of this library.

Four new logging classes are available out of the box:

1. Google_Logger_Abstract: This abstract class implements most of the
functionality required for a logger. The only detail that is left to the
concrete classes is the `write()` method. If you want to create a custom
logger, you should extend this class.

2. Google_Logger_Null: This logger simply discards all messages. You can use
this logger to ensure that no messages will be logged. This is the default
logger.

3. Google_Logger_File: This logger will write messages to just about any
writable stream resource you give it.

4. Google_Logger_Psr: This logger exists to allow for interoperability with
other PSR-3 logging systems. All you need to do is provide this logger
with and instance of another logger and you're done. Below is an
example of integrating with Monolog:

~~~php
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$monolog = new Logger('Google API');
$monolog->pushHandler(new StreamHandler('php://output', Logger::INFO));

$config = new Google_Config();
$config->setLoggerClass('Google_Logger_Psr');

$client = new Google_Client($config);
$client->getLogger()->setLogger($monolog);

// Logs: [2014-11-16 16:28:21] Google API.INFO: Service Call {"service":"books"...
$service = new Google_Service_Books($client);
$service->volumes->listVolumes('Henry David Thoreau');

// Logs: [2014-11-16 16:28:21] Google API.ERROR: My custom error
$client->getLogger()->error('My custom error');
~~~