├── .gitignore ├── README.md ├── composer.json ├── modman └── src └── app ├── code └── community │ └── EmPeWe │ └── ApiLogger │ ├── Helper │ ├── Data.php │ ├── V1.php │ └── V2.php │ ├── Model │ └── Server │ │ ├── Handler.php │ │ └── V2 │ │ └── Handler.php │ └── etc │ ├── config.xml │ └── system.xml └── etc └── modules └── EmPeWe_ApiLogger.xml /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Magento SOAP API Logger 2 | ======================= 3 | 4 | Facts 5 | ----- 6 | - version: 0.0.8 7 | - [extension on GitHub](https://github.com/EmPeWe/magento-api-logger) 8 | 9 | Description 10 | ----------- 11 | This Magento extensions allow the API calls to be logged. At the moment only SOAP API v1/v2 could be logged. 12 | 13 | Requirements 14 | ------------ 15 | - PHP >= 5.2.0 16 | - Mage_Core 17 | 18 | Compatibility 19 | ------------- 20 | - Tested on Magento CE 1.8.1.0 - 1.9.1 and EE 1.13.1 - 1.14.1, but should work with older versions too 21 | 22 | Installation Instructions 23 | ------------------------- 24 | 1. Install/Deploy the extension via modman or copy all the files into your document root. 25 | 2. Clear the cache, logout from the admin panel and then login again. 26 | 3. Configure and activate the extension under System - Configuration - EMPEWE - SOAP ApiLogger. 27 | 28 | Hints 29 | ----- 30 | 1. ~~The logger will only work, if the global log settings (System -> Configuration -> Developer -> Log Settings) are active.~~ 31 | 2. If you installed the extensions with modman, don't forget to allow Symlinks (System -> Configuration -> Developer -> Template Settings) 32 | 33 | Uninstallation 34 | -------------- 35 | 1. Remove all extension files from your Magento installation 36 | 2. Delete all entry from core_config_data with path starting like 'apilogger_options/config/%' 37 | 38 | Support 39 | ------- 40 | If you have any issues with this extension, open an issue on [GitHub](https://github.com/EmPeWe/magento-api-logger/issues). 41 | 42 | Contribution 43 | ------------ 44 | Any contribution is highly appreciated. The best way to contribute code is to open a [pull request on GitHub](https://help.github.com/articles/using-pull-requests). 45 | 46 | Copyright 47 | --------- 48 | (c) 2014-2016 EmPeWe 49 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "empewe/magento-api-logger", 3 | "license": "Beerware", 4 | "type": "magento-module", 5 | "description": "Magento extensions to log SOAP API calls", 6 | "keywords": 7 | [ 8 | "magento", 9 | "api", 10 | "logging", 11 | "events" 12 | ], 13 | "homepage": "https://github.com/EmPeWe/magento-api-logger", 14 | "require": 15 | { 16 | "php": ">5.2", 17 | "magento-hackathon/magento-composer-installer": "*" 18 | }, 19 | "authors": 20 | [ 21 | { 22 | "name": "Manuel Weinstein", 23 | "homepage": "https://github.com/EmPeWe", 24 | "role": "Developer" 25 | } 26 | ], 27 | "support": 28 | { 29 | "source": "https://github.com/EmPeWe/magento-api-logger", 30 | "issues": "https://github.com/EmPeWe/magento-api-logger/issues" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /modman: -------------------------------------------------------------------------------- 1 | src/app/code/community/EmPeWe/ApiLogger app/code/community/EmPeWe/ApiLogger 2 | src/app/etc/modules/* app/etc/modules/ -------------------------------------------------------------------------------- /src/app/code/community/EmPeWe/ApiLogger/Helper/Data.php: -------------------------------------------------------------------------------- 1 | getIsActive() || ($response === null && !$this->getIsVerboseEnabled())) { 50 | return; 51 | } 52 | 53 | $log = "SOAP Method (V1): {$apiPath}"; 54 | 55 | $log .= "\nRequest ID: {$requestId}"; 56 | 57 | $apiUser = $this->getSession()->getUser(); 58 | if ($apiUser instanceof Mage_Api_Model_User) { 59 | $log .= sprintf("\nAPI User: %s (ID: %s)", $apiUser->getUsername(), $apiUser->getId()); 60 | } 61 | 62 | $log .= "\nCalled from IP: {$this->getRemoteAddr()}"; 63 | $log .= "\nUser Agent: {$this->getHttpUserAgent()}"; 64 | $log .= "\nParameters: " . print_r(array_merge((array)$sessionId, $args), true); 65 | 66 | if ($this->getIsVerboseEnabled()) { 67 | $log .= "\nResponse: " . print_r($response, true); 68 | } 69 | 70 | if ($exception) { 71 | $log .= "\nException: {$exception}"; 72 | } 73 | 74 | $logLevel = ($exception ? Zend_Log::WARN : Zend_Log::DEBUG); 75 | 76 | Mage::log($log, $logLevel, $this->getLogFilename(), $this->getForceLog()); 77 | } 78 | 79 | /** 80 | * @return string 81 | */ 82 | protected function getRemoteAddr() 83 | { 84 | return Mage::helper('core/http')->getRemoteAddr(); 85 | } 86 | 87 | /** 88 | * @return string 89 | */ 90 | protected function getHttpUserAgent() 91 | { 92 | return Mage::helper('core/http')->getHttpUserAgent(); 93 | } 94 | 95 | /** 96 | * Retrieve webservice session 97 | * 98 | * @return Mage_Api_Model_Session 99 | */ 100 | protected function getSession() 101 | { 102 | return Mage::getSingleton('api/session'); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/app/code/community/EmPeWe/ApiLogger/Helper/V2.php: -------------------------------------------------------------------------------- 1 | getIsActive() || ($response === null && !$this->getIsVerboseEnabled())) { 44 | return; 45 | } 46 | 47 | $log = "SOAP Method (V2): {$function}"; 48 | 49 | $log .= "\nRequest ID: {$requestId}"; 50 | 51 | $apiUser = $this->getSession()->getUser(); 52 | if ($apiUser instanceof Mage_Api_Model_User) { 53 | $log .= sprintf("\nAPI User: %s (ID: %s)", $apiUser->getUsername(), $apiUser->getId()); 54 | } 55 | 56 | $log .= "\nCalled from IP: {$this->getRemoteAddr()}"; 57 | $log .= "\nUser Agent: {$this->getHttpUserAgent()}"; 58 | $log .= "\nParameters: " . print_r($args, true); 59 | 60 | if ($this->getIsVerboseEnabled()) { 61 | $log .= "\nResponse: " . print_r($response, true); 62 | } 63 | 64 | if ($exception) { 65 | $log .= "\nException: {$exception}"; 66 | } 67 | 68 | $logLevel = ($exception ? Zend_Log::WARN : Zend_Log::DEBUG); 69 | 70 | Mage::log($log, $logLevel, $this->getLogFilename(), $this->getForceLog()); 71 | } 72 | 73 | /** 74 | * @return string 75 | */ 76 | protected function getRemoteAddr() 77 | { 78 | return Mage::helper('core/http')->getRemoteAddr(); 79 | } 80 | 81 | /** 82 | * @return string 83 | */ 84 | protected function getHttpUserAgent() 85 | { 86 | return Mage::helper('core/http')->getHttpUserAgent(); 87 | } 88 | 89 | /** 90 | * Retrieve webservice session 91 | * 92 | * @return Mage_Api_Model_Session 93 | */ 94 | protected function getSession() 95 | { 96 | return Mage::getSingleton('api/session'); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/app/code/community/EmPeWe/ApiLogger/Model/Server/Handler.php: -------------------------------------------------------------------------------- 1 | generateRequestId($sessionId); 8 | 9 | $helper = $this->getHelper(); 10 | 11 | try { 12 | $helper->log($requestId, $sessionId, $apiPath, $args); 13 | 14 | $response = parent::call($sessionId, $apiPath, $args); 15 | 16 | $helper->log($requestId, $sessionId, $apiPath, $args, $response); 17 | 18 | return $response; 19 | } catch (Exception $e) { 20 | $helper->log($requestId, $sessionId, $apiPath, $args, isset($response) ? $response : null, $e); 21 | 22 | throw $e; 23 | } 24 | } 25 | 26 | /** 27 | * @return EmPeWe_ApiLogger_Helper_V1 28 | */ 29 | protected function getHelper() 30 | { 31 | return Mage::helper('empewe_apilogger/v1'); 32 | } 33 | 34 | /** 35 | * @param string $sessionId 36 | * @return string 37 | */ 38 | protected function generateRequestId($sessionId) 39 | { 40 | return uniqid($sessionId . '_', true); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/app/code/community/EmPeWe/ApiLogger/Model/Server/V2/Handler.php: -------------------------------------------------------------------------------- 1 | generateRequestId($sessionId); 10 | 11 | $helper = $this->getHelper(); 12 | 13 | try { 14 | $helper->log($requestId, $function, $args); 15 | 16 | $response = parent::__call($function, $args); 17 | 18 | $helper->log($requestId, $function, $args, $response); 19 | 20 | return $response; 21 | } catch (Exception $e) { 22 | $helper->log($requestId, $function, $args, isset($response) ? $response : null, $e); 23 | 24 | throw $e; 25 | } 26 | } 27 | 28 | /** 29 | * @return EmPeWe_ApiLogger_Helper_V2 30 | */ 31 | protected function getHelper() 32 | { 33 | return Mage::helper('empewe_apilogger/v2'); 34 | } 35 | 36 | /** 37 | * @param string $sessionId 38 | * @return string 39 | */ 40 | protected function generateRequestId($sessionId) 41 | { 42 | return uniqid($sessionId . '_', true); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/app/code/community/EmPeWe/ApiLogger/etc/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 0.0.8 6 | 7 | 8 | 9 | 10 | 11 | EmPeWe_ApiLogger_Helper 12 | 13 | 14 | 15 | 16 | EmPeWe_ApiLogger_Model 17 | 18 | 19 | 20 | EmPeWe_ApiLogger_Model_Server_Handler 21 | EmPeWe_ApiLogger_Model_Server_V2_Handler 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 1 30 | EmPeWe_ApiLogger.log 31 | 1 32 | EmPeWe_ApiLogger.log 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | Allow Everything 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | EmPeWe - All 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/app/code/community/EmPeWe/ApiLogger/etc/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 99999 6 | 7 | 8 | 9 | 10 | 11 | apilogger_config 12 | text 13 | 1000 14 | 1 15 | 1 16 | 1 17 | 18 | 19 | 20 | text 21 | 1 22 | 1 23 | 1 24 | 1 25 | 26 | 27 | 28 | Don't forget to deactivate before going live! 29 | select 30 | 10 31 | 1 32 | 1 33 | 1 34 | adminhtml/system_config_source_yesno 35 | 36 | 37 | 38 | Log response returned 39 | select 40 | 20 41 | 1 42 | 1 43 | 1 44 | adminhtml/system_config_source_yesno 45 | 46 | 47 | 48 | Default is EmPeWe_ApiLogger.log 49 | text 50 | 30 51 | 1 52 | 1 53 | 1 54 | 55 | 56 | 57 | Don't forget to deactivate before going live! 58 | select 59 | 40 60 | 1 61 | 1 62 | 1 63 | adminhtml/system_config_source_yesno 64 | 65 | 66 | 67 | Log response returned 68 | select 69 | 50 70 | 1 71 | 1 72 | 1 73 | adminhtml/system_config_source_yesno 74 | 75 | 76 | 77 | Default is EmPeWe_ApiLogger.log 78 | text 79 | 60 80 | 1 81 | 1 82 | 1 83 | 84 | 85 | 86 | Log even, if system logging is deactivated 87 | select 88 | 70 89 | 1 90 | 1 91 | 1 92 | adminhtml/system_config_source_yesno 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /src/app/etc/modules/EmPeWe_ApiLogger.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | community 7 | 8 | 9 | 10 | --------------------------------------------------------------------------------