This repository has been archived by the owner on Sep 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
Custom Logger
Rafal W edited this page May 20, 2017
·
4 revisions
Since, v1.7.0, PayPal PHP SDK supports custom logger injection. This allows developers to extend their own logging implementation to PHP SDK.
- Create a class implementing PayPalLogFactory. Look at PayPalDefaultLogFactory for reference. Here is an example CustomLogFactory using Monolog Logger:
use PayPal\Log\PayPalLogFactory;
use Psr\Log\LoggerInterface;
class MonologLogFactory implements PayPalLogFactory
{
/**
* Returns logger instance implementing LoggerInterface.
*
* @param string $className
* @return LoggerInterface instance of logger object implementing LoggerInterface
*/
public function getLogger($className)
{
$logger = new Monolog\Logger($className);
$logger->pushHandler(new Monolog\Handler\StreamHandler("mail.log"));
return $logger;
}
}
- Set
log.AdapterFactory
settings in your$apiContext->setConfig()
method as shown below:
$apiContext->setConfig(
array(
...
'log.LogEnabled' => true,
'log.FileName' => '../PayPal.log',
'log.LogLevel' => 'DEBUG',
'log.AdapterFactory' => 'MonologLogFactory' // Factory class implementing \PayPal\Log\PayPalLogFactory
...
)
);
- Thats it. Run some samples, and see the
mail.log
file getting created and logged with debug messages. - NOTE: be sure to add
monolog\monolog
as a dependency in composer for this example.
Getting Started
Using Our SDK
Configurations
Extras
External Links