Logging
The PHP-SDK does not specify a dependency on any logging packages, meaning no logging will be performed out of the box. This is an intentional design decision to ensure better integration with existing system.
If you wish to enable logging, you will need to install a package which contains an implementation of Psr\Log\LoggerInterface
While any class which implements the PSR Logger interface is supported, we recommend using the Monolog package, which is already present in many of the major frameworks.
You can install this in your application via composer:
composer require monolog/monologAll services which interact with Klevu's APIs accept a logger instance via their constructor; the only other class which implements logging at time of writing is the RequestBearerTokenProvider , which generates an authentication token for indexing.
Note: If you are integrating into a modern framework, you should implement this via your dependency injection system
<?php
declare(strict_types=1);
use Klevu\PhpSDK\Provider\RequestBearerTokenProvider;
use Klevu\PhpSDK\Service\Account\AccountFeaturesService;
use Klevu\PhpSDK\Service\Account\AccountLookupService;
use Klevu\PhpSDK\Service\Account\UpdateStoreFeedUrlService;
use Klevu\PhpSDK\Service\Analytics\CollectService as AnalyticsCollectService;
use Klevu\PhpSDK\Service\Indexing\AttributesService;
use Klevu\PhpSDK\Service\Indexing\Batch\DeleteService as BatchDeleteService;
use Klevu\PhpSDK\Service\Indexing\BatchService;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
// Create a new logger instance, writing to the /app/logs directory
// with separate files for debugging and errors-only
$logger = new Logger(
name: 'app',
handlers: [
new StreamHandler('/app/logs/error.log', Logger::ERROR),
new StreamHandler('/app/logs/debug.log', Logger::DEBUG),
],
);
// Account
$accountFeatureService = new AccountFeaturesService(
logger: $logger,
);
$accountLookupService = new AccountLookupService(
logger: $logger,
);
$updateStoreFeedUrlService = new UpdateStoreFeedUrlService(
logger: $logger,
);
// Analytics
$collectService = new AnalyticsCollectService(
logger: $logger,
);
// Indexing
$attributesService = new AttributesService(
logger: $logger,
);
$batchService = new BatchService(
logger: $logger,
);
$batchDeleteService = new BatchDeleteService(
logger: $logger,
);
$requestBearerTokenProvider = new RequestBearerTokenProvider(
logger: $logger,
);
Once implemented, you should start seeing PHP-SDK related logs written to the files specified when creating the Logger.