1
0

Beta Release 0.5.0 (#3)

* Automated commit message

* Automated commit message

* Automated commit message

* Automated commit message

---------

Co-authored-by: PayPalServerSDKs <server-sdks@paypal.com>
This commit is contained in:
Dani Kirby
2024-09-09 12:10:34 -05:00
committed by GitHub
parent c9cb1ad04a
commit 6b43a4225b
732 changed files with 73569 additions and 1 deletions

View File

@@ -0,0 +1,50 @@
# LoggingConfigurationBuilder Class
Represents the logging configurations for API calls. Create instance using `LoggingConfigurationBuilder::init()`
## Methods
| Name | Parameter Type | Description |
| --- | --- | --- |
| logger | `LoggerInterface` | Takes in your custom implementation of the Psr\Log\LoggerInterface.php. **Default Implementation : `ConsoleLogger`** |
| level | `string(LogLevel)` | Defines the log message severity mentioned in Psr\Log\LogLevel.php (e.g., DEBUG, INFO, etc). **Default : `logLevel::INFO`** |
| maskSensitiveHeaders | `bool` | Toggles the global setting to mask sensitive HTTP headers in both requests and responses before logging, safeguarding confidential data. **Default : `true`** |
| requestConfiguration | [`RequestLoggingConfigurationBuilder`](request-logging-configuration-builder.md) | The logging configurations for an API request. |
| responseConfiguration | [`RequestLoggingConfigurationBuilder`](response-logging-configuration-builder.md) | The logging configurations for an API response. |
## Usage Example
### Client Initialization with Custom Logger
In order to provide custom logger, any implementation of the `Psr\Log\LoggerInterface` can be used so that you can override the `log` behavior and provide its instance directly in the SDK client initialization.
The following example uses `Monolog\Logger` implementation of `Psr\Log\LoggerInterface` for PaypalServerSDKClient initialization.
```php
<?php
use PaypalServerSDKLib\PaypalServerSDKClientBuilder;
use PaypalServerSDKLib\Logging\LoggingConfigurationBuilder;
use PaypalServerSDKLib\Logging\RequestLoggingConfigurationBuilder;
use PaypalServerSDKLib\Logging\ResponseLoggingConfigurationBuilder;
use Psr\Log\LogLevel;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
// create a log channel
$logger = new Logger('PaypalServerSDK');
$logger->pushHandler(new StreamHandler(__DIR__ . '/api_data.log'));
// initialize the sdk client using this logger
$client = PaypalServerSDKClientBuilder::init()
->loggingConfiguration(
LoggingConfigurationBuilder::init()
->logger($logger)
->level(LogLevel::INFO)
->requestConfiguration(RequestLoggingConfigurationBuilder::init()->body(true))
->responseConfiguration(ResponseLoggingConfigurationBuilder::init()->headers(true))
)
->build();
```