1

While writing a module, an observer had an undefined variable, which would typically create an E_NOTICE error. However, I also had the Magento Developer Mode enabled. So when Abstract.php caught the error, it sent it over to Mage::printException it did not log it any where. The module was part of an ajax call, the result was that I never saw the error.

Do people actually use Magento developer mode? It is starting to seem counter productive without overriding the Magento core.

Does anyone have a solution to log all errors, even when in Developer mode? Am I missing something or is modifying Mage.php the only way?

1

Have a look on Mage::printException(). Mainly it has two parts and I will give you a brief Idea.

public static function printException(Exception $e, $extra = '')
{
    if (self::$_isDeveloperMode) {
        print '<pre>';

        if (!empty($extra)) {
            print $extra . "\n\n";
        }

        print $e->getMessage() . "\n\n";
        print $e->getTraceAsString();
        print '</pre>';
    } else {

        $reportData = array(
            !empty($extra) ? $extra . "\n\n" : '' . $e->getMessage(),
            $e->getTraceAsString()
        );

        // retrieve server data
        if (isset($_SERVER)) {
            if (isset($_SERVER['REQUEST_URI'])) {
                $reportData['url'] = $_SERVER['REQUEST_URI'];
            }
            if (isset($_SERVER['SCRIPT_NAME'])) {
                $reportData['script_name'] = $_SERVER['SCRIPT_NAME'];
            }
        }

        // attempt to specify store as a skin
        try {
            $storeCode = self::app()->getStore()->getCode();
            $reportData['skin'] = $storeCode;
        }
        catch (Exception $e) {}

        require_once(self::getBaseDir() . DS . 'errors' . DS . 'report.php');
    }

    die();
}

So when Developer Mode is on, this is what happens.

if (self::$_isDeveloperMode) {
        print '<pre>';

        if (!empty($extra)) {
            print $extra . "\n\n";
        }

        print $e->getMessage() . "\n\n";
        print $e->getTraceAsString();
        print '</pre>';
    }
    die();

In short, it prints the error on the browser and then die.

But if it is not in developer mode, it will actually log the error (actually more details) in var/report/ directory.

You have specified in your question that, module which is responsible for triggering Mage::printException() is used as a part of ajax request. I think this is why you are not viewing the printed error on your browser (since you are in developer mode). Most probably you can see the error in your Browser console.

  • I can... My solution was to inject a Mage::logException($e) at the end of printException in developer mode. That begs the question, what's the point of developer mode anyway? Specially if you do everything with a tail -f magento/var/log/* – Ray Foss Apr 1 '15 at 11:45
  • developer mode means you can see error hint directly on browser rather than log it. This is logical since, it shows error instantly on browser during development and hence we do not want to look into var/report/* folder. If you want to log the exception then go on with customization. – Rajeev K Tomy Apr 1 '15 at 13:21
  • "it shows error instantly on browser" Thats exactly the problem, the browser may refresh, the request could have been done by javascript or an internal php dummy connection, it could have been done from an api on a server etc... logging should not be disabled in developer mode, even if it may be displayed on the client. Thanks for the response. – Ray Foss May 29 '15 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.