Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JosephMaxwell/57d971554de9ddb4e2333119301c5714 to your computer and use it in GitHub Desktop.
Save JosephMaxwell/57d971554de9ddb4e2333119301c5714 to your computer and use it in GitHub Desktop.
Quickly get the stack trace using Magento's Object Manager (hotfix)

This is NOT a best practice and is ONLY for an emergency situation. However, it is good to use the LoggerInterface throughout your code and add generous parameters to the array.

// Generate an exception so we can get the stack trace.
// We could use debug_backtrace, but it's easy to arguments and thus take the site down.
$ex = new Exception();

// Log it out. Don't forget the critically-helpful parameters array. Put anything
// and everything here.
\Magento\Framework\App\ObjectManager::getInstance()
    ->get(\Psr\Log\LoggerInterface::class)->critical('Important notification for:', [
        'trace' => $ex->getTraceAsString(),
        'order_id' => $order->getId()
    ]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment