|
| 1 | +Logging |
| 2 | +============ |
| 3 | + |
| 4 | +The library allows logging to be added via Guzzle's Log Plugin [http://guzzle3.readthedocs.org/plugins/log-plugin.html] which supports logs via a variety of adapters. |
| 5 | + |
| 6 | +Example: |
| 7 | +================================================== |
| 8 | + |
| 9 | +This example adds basic logging using the Zend Framework 2 Logging [http://framework.zend.com/manual/2.3/en/modules/zend.log.overview.html] and sending output to the buffer |
| 10 | + |
| 11 | +.. code:: php |
| 12 | +
|
| 13 | + require_once('vendor/autoload.php'); |
| 14 | +
|
| 15 | + use OCLC\Auth\WSKey; |
| 16 | + use OCLC\Auth\AccessToken; |
| 17 | + use WorldCat\Discovery\Bib; |
| 18 | + |
| 19 | + use Guzzle\Plugin\Log\LogPlugin; |
| 20 | + use Guzzle\Log\MessageFormatter; |
| 21 | + use Guzzle\Log\Zf2LogAdapter; |
| 22 | + use Zend\Log\Logger; |
| 23 | + use Zend\Log\Writer\Stream |
| 24 | + |
| 25 | + $key = 'api-key'; |
| 26 | + $secret = 'api-key-secret'; |
| 27 | + $options = array('services' => array('WorldCatDiscoveryAPI', 'refresh_token')); |
| 28 | + $wskey = new WSKey($key, $secret, $options); |
| 29 | + $accessToken = $wskey->getAccessTokenWithClientCredentials('128807', '128807')); |
| 30 | + |
| 31 | + $logwriter = new Stream('php://output'); |
| 32 | + $logger = new Logger(); |
| 33 | + $logger->addWriter($logwriter); |
| 34 | + $adapter = new Zf2LogAdapter($logger); |
| 35 | + $logPlugin = new LogPlugin($adapter, MessageFormatter::DEBUG_FORMAT); |
| 36 | + $options = array( |
| 37 | + 'logger' => $logPlugin |
| 38 | + ); |
| 39 | + $bib = Bib::find(7977212, $accessToken, $options); |
| 40 | + |
| 41 | +Example: |
| 42 | +================================================== |
| 43 | + |
| 44 | +This example adds basic logging using the Zend Framework 2 Logging [http://framework.zend.com/manual/2.3/en/modules/zend.log.overview.html] and sending output to the filesystem |
| 45 | + |
| 46 | +.. code:: php |
| 47 | +
|
| 48 | + require_once('vendor/autoload.php'); |
| 49 | +
|
| 50 | + use OCLC\Auth\WSKey; |
| 51 | + use OCLC\Auth\AccessToken; |
| 52 | + use WorldCat\Discovery\Bib; |
| 53 | + |
| 54 | + use Guzzle\Plugin\Log\LogPlugin; |
| 55 | + use Guzzle\Log\MessageFormatter; |
| 56 | + use Guzzle\Log\Zf2LogAdapter; |
| 57 | + use Zend\Log\Logger; |
| 58 | + use Zend\Log\Writer\Stream |
| 59 | + |
| 60 | + $key = 'api-key'; |
| 61 | + $secret = 'api-key-secret'; |
| 62 | + $options = array('services' => array('WorldCatDiscoveryAPI', 'refresh_token')); |
| 63 | + $wskey = new WSKey($key, $secret, $options); |
| 64 | + $accessToken = $wskey->getAccessTokenWithClientCredentials('128807', '128807')); |
| 65 | + |
| 66 | + $logwriter = new Stream('/path/to/logfile'); |
| 67 | + $logger = new Logger(); |
| 68 | + $logger->addWriter($logwriter); |
| 69 | + $adapter = new Zf2LogAdapter($logger); |
| 70 | + $logPlugin = new LogPlugin($adapter, MessageFormatter::DEBUG_FORMAT); |
| 71 | + $options = array( |
| 72 | + 'logger' => $logPlugin |
| 73 | + ); |
| 74 | + $bib = Bib::find(7977212, $accessToken, $options); |
0 commit comments