Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento's Mage::log() causes white screen

Tags:

php

magento

When using Magentos log facility Mage::log() it sometimes causes a white screen. No error messages are outputted either to the screen or any of the log files (var/log/system.log, var/log/exception.log )

This seems to happen only when I'm trying to log a very large object. for example when I'm trying this

Mage::log(Mage::helper('catalog/category')->getStoreCategories());

inside a block controller it causes a white screen.
the same happens when I'm trying to log the current product in app/design/frontend/enterprise/default/template/catalog/product/view/media.phtml using

Mage::log($_product);

Usually Mage::log() works fine and writes everything to the system.log file.
I was wondering if this has happened to anybody else or if anybody has an idea about why this is happening?

like image 341
clem Avatar asked Dec 22 '22 02:12

clem


2 Answers

Mage::log works a lot like print_r, private and protected values are printed too which includes extensive resource details. You can avoid these by using the purpose made Varien_Object::debug method.

Mage::log($_product->debug());

debug is also preferred because it detects recursion which not all versions of PHP do.

like image 193
clockworkgeek Avatar answered Dec 24 '22 03:12

clockworkgeek


I guess it happens to everyone.

Try not to log large objects.

In case you need I would advice you to use die.

for example like this

    $object = ...;
    die($object);
or
    die('pre html tag'.print_r($object,true).'pre html tag');
like image 25
Jevgeni Smirnov Avatar answered Dec 24 '22 02:12

Jevgeni Smirnov