Examples / How To

Logging

2min
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 bash composer require monolog/monolog all 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