From 6b6592a2a64e395831b198921dd86f9411bc64a6 Mon Sep 17 00:00:00 2001 From: Ebano Lopes Date: Fri, 10 Jan 2020 12:52:48 +0000 Subject: [PATCH] 3.6.0: MAG-517: Improve debug logs --- Observer/Debug/Order.php | 121 +++++++++++++++++++++++++++ Plugin/Magento/Sales/Model/Order.php | 49 +---------- composer.json | 2 +- etc/events.xml | 1 + etc/module.xml | 2 +- 5 files changed, 125 insertions(+), 50 deletions(-) create mode 100644 Observer/Debug/Order.php diff --git a/Observer/Debug/Order.php b/Observer/Debug/Order.php new file mode 100644 index 00000000..602a5eff --- /dev/null +++ b/Observer/Debug/Order.php @@ -0,0 +1,121 @@ +logger = $logger; + $this->configHelper = $configHelper; + $this->url = $url; + } + + public function execute(Observer $observer) + { + try { + /** @var $order \Magento\Sales\Model\Order */ + $order = $observer->getEvent()->getOrder(); + + $log = $this->configHelper->getConfigData('signifyd/logs/log', $order); + + // Log level 2 => debug + if ($log == 2) { + $state = $order->getState(); + $currentState = $order->getOrigData('state'); + + if ($state <> $currentState) { + $incrementId = $order->getIncrementId(); + + $this->logger->debug("Order {$incrementId} state change from {$currentState} to {$state}"); + $this->logger->debug("Request URL: {$this->url->getCurrentUrl()}"); + + $debugBacktrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + $debugBacktraceLog = []; + $nonMagentoModules = []; + + foreach ($debugBacktrace as $i => $step) { + $debugBacktraceLog[$i] = []; + $function = ''; + + if (isset($step['class'])) { + $function .= $step['class']; + + if ($step['class'] != \Signifyd\Connect\Plugin\Magento\Sales\Model\Order::class) { + list($vendor, $module, $class) = explode('\\', $step['class'], 3); + + if ($vendor != "Magento") { + $nonMagentoModules["{$vendor}\\{$module}"] = ''; + } + } + } + + if (isset($step['type'])) { + $function .= $step['type']; + } + + if (isset($step['function'])) { + $function .= $step['function']; + } + + $debugBacktraceLog[$i][] = "\t[{$i}] {$function}"; + + $file = isset($step['file']) ? str_replace(BP, '', $step['file']) : false; + + if ($file !== false) { + $debugBacktraceLog[$i][] = "line {$step['line']} on {$file}"; + } + + $debugBacktraceLog[$i] = implode(', ', $debugBacktraceLog[$i]); + } + + if (empty($nonMagentoModules) == false) { + $nonMagentoModulesList = implode(', ', array_keys($nonMagentoModules)); + $this->logger->debug("WARNING: non Magento modules found on backtrace: {$nonMagentoModulesList}"); + } + + $debugBacktraceLog = implode("\n", $debugBacktraceLog); + $this->logger->debug("Backtrace: \n{$debugBacktraceLog}\n\n"); + } + } + } catch (\Exception $e) { + } + } +} \ No newline at end of file diff --git a/Plugin/Magento/Sales/Model/Order.php b/Plugin/Magento/Sales/Model/Order.php index a7780d92..fa5b170d 100644 --- a/Plugin/Magento/Sales/Model/Order.php +++ b/Plugin/Magento/Sales/Model/Order.php @@ -54,55 +54,8 @@ public function beforeSetState(\Magento\Sales\Model\Order $subject, $state) $currentState = $subject->getState(); $incrementId = $subject->getIncrementId(); - $this->logger->debug("Order {$incrementId} state change from {$currentState} to {$state}"); + $this->logger->debug("setState on order {$incrementId} state change from {$currentState} to {$state}"); $this->logger->debug("Request URL: {$this->url->getCurrentUrl()}"); - - $debugBacktrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - $debugBacktraceLog = []; - $nonMagentoModules = []; - - foreach ($debugBacktrace as $i => $step) { - $debugBacktraceLog[$i] = []; - $function = ''; - - if (isset($step['class'])) { - $function .= $step['class']; - - if ($step['class'] != \Signifyd\Connect\Plugin\Magento\Sales\Model\Order::class) { - list($vendor, $module, $class) = explode('\\', $step['class'], 3); - - if ($vendor != "Magento") { - $nonMagentoModules["{$vendor}\\{$module}"] = ''; - } - } - } - - if (isset($step['type'])) { - $function .= $step['type']; - } - - if (isset($step['function'])) { - $function .= $step['function']; - } - - $debugBacktraceLog[$i][] = "\t[{$i}] {$function}"; - - $file = isset($step['file']) ? str_replace(BP, '', $step['file']) : false; - - if ($file !== false) { - $debugBacktraceLog[$i][] = "line {$step['line']} on {$file}"; - } - - $debugBacktraceLog[$i] = implode(', ', $debugBacktraceLog[$i]); - } - - if (empty($nonMagentoModules) == false) { - $nonMagentoModulesList = implode(', ', array_keys($nonMagentoModules)); - $this->logger->debug("WARNING: non Magento modules found on backtrace: {$nonMagentoModulesList}"); - } - - $debugBacktraceLog = implode("\n", $debugBacktraceLog); - $this->logger->debug("Backtrace: \n{$debugBacktraceLog}\n\n"); } } catch (\Exception $e) { $this->logger->debug('Exception logging order state change: ' . $e->getMessage()); diff --git a/composer.json b/composer.json index 67e7b82b..22bc7f0f 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "php": ">=5.5.22" }, "type": "magento2-module", - "version": "3.5.1", + "version": "3.6.0", "autoload": { "files": [ "registration.php" diff --git a/etc/events.xml b/etc/events.xml index 16b19b64..a4d8cbde 100644 --- a/etc/events.xml +++ b/etc/events.xml @@ -5,6 +5,7 @@ + diff --git a/etc/module.xml b/etc/module.xml index 1f8ced4e..3e9eac3c 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -5,7 +5,7 @@ */ --> - +