Magento Forum

   
HowTo: Quick and dirty file logging
 
teemu_m
Jr. Member
 
Avatar
Total Posts:  24
Joined:  2007-11-19
Salo - Finland
 

I needed a quick and simple way to log debug information into a file. In case you’re looking something similar (and it appears many are), and since the information is a bit scattered around the forum, here is what I did (Magento ver. 1.0.19870.1):

Enable file logging:
Admin Panel > System > Configuration > Advanced/Developer > Log Settings > Enabled = Yes

From now on watch {installBaseDir}/var/log/system.log
(log directory and system.log file are automatically created during first file logging)

Drop this line into the code you’re debugging (minimalistic example):

Mage::log('WTH!');

Resulting minimalistic file log:

2008-06-05T09:10:29+00:00 DEBUG (7): WTH!

A bit more informative example:

$anyVar 'Fubar'//Any type of variable

if (Mage::getStoreConfig('dev/log/active')) //Don't bother logging if logging isn't enabled
    
Mage::log("\n".__FILE__." (".__LINE__.")\n".__METHOD__."\n".print_r($anyVartrue));
}

Resulting file log:

2008-06-05T09:10:29+00:00 DEBUG (7): 
/var/
www/mage/app/code/local/Mage/Fipn/Model/Standard.php (448)
Mage_Fipn_Model_Standard::getStandardCheckoutFormFields
Fubar

You may empty or delete the system.log file any time you wish.

It would be nice to hear about more advanced debugging methods. Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
WebShopApps
Guru
 
Avatar
Total Posts:  460
Joined:  2008-05-30
London, UK
 

Thanks for this tip and example, is very helpful.  I keep returning to it!!

Karen

 
Magento Community Magento Community
Magento Community
Magento Community
 
chiefair
Mentor
 
Avatar
Total Posts:  1839
Joined:  2009-06-04
 

Or define your own log file so you don’t have to search through the system log:

Mage::log('errortolog ' ,null,'yourlog.log');

As an example of getting the raw XML Response from UPS…

Mage::log('UPS Response: ' $xmlResponse,null,'ups_response.log');

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top