Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento API Logs

Tags:

magento

Is there any way to turn on logging for API calls?

We have a third party application that is having trouble working with our store and would like to get some debuggging info. ~I have searched bt found nothing.

I'm using 1.7

like image 628
Matthew Dolman Avatar asked Aug 23 '12 04:08

Matthew Dolman


People also ask

What is system log in Magento 2?

Logs provide insight into system processes of Magento 2 and are a great tool for tracking errors, significant events, exceptions and many more. In order for the logging library to be properly implemented with Magento 2, it must comply with PSR-3 standard.

What is API in magento2?

Magento API is a type of framework that offers developers and integrators a good method to maximize web services which communicate well with the Magneto system. Amongst the primary features are supports for SOAP (Simple Object Access Protocol) and REST (Representation State Transfer).


2 Answers

for a controlled period of time you can manipulate your index.php like so:

put this code at the end of the index.php around the ::run call:

ob_start();
Mage::run($mageRunCode, $mageRunType);

if(preg_match('/api/', $_SERVER['REQUEST_URI'])) {
        Mage::log('<<< request '.$_SERVER['REQUEST_METHOD'].': '.$_SERVER['REQUEST_URI'], null, 'api.log');
        if($_SERVER['REQUEST_METHOD'] == 'POST') {
                Mage::log('<<< '.file_get_contents('php://input'), null, 'api.log');
        }
        Mage::log('>>> '.ob_get_contents(), null, 'api.log');
}

ob_end_flush();

its quick and dirty but for adhoc debugging it works

like image 199
greenone83 Avatar answered Oct 30 '22 10:10

greenone83


A really good solution is to use an API proxy. It's not as complex as it sounds. It's just a PHP script you point your API calls to instead of the the normal API URL. The idea is that it logs every incoming API request before passing it onto the normal magento API. It also logs the responses before passing it back to the client.

There's a ready built one right here which I've used in the past to diagnose many API issues. http://techcolin.net/2011/11/a-php-proxy-script-for-logging-magento-api-soap-calls/

like image 35
elMarquis Avatar answered Oct 30 '22 11:10

elMarquis