Quick debugging tip
Posted on 03. Sep, 2008 by Fido in Development, Magento, Module
You can add items to magento’s system log and exception log in your code. This is very handy for pin-pointing coding errors / problems. Developing for Magento is often hard, especially since it’s not always possibly to have error reporting on (and even when it is on, its hard to find exactly what’s wrong!).
Here’s an example of it’s use:
1) Turn on your logging: Admin > Configuration > Developer > Log Settings > Enabled = Yes
2) Example code snippet where you might find this useful:
<?php $response = curl_exec($ch); //just an example of something - might use this in a custom payment or shipping module Mage::log($responseBody); ?>
3) Watch your var/log/system.log and var/log/exception.log for raw information from this.
You may run into file permission errors, so you might need to set your folder permissions appropriately




8 Comments
aledujke
07. Nov, 2008
I’m currently working with observers and this helped me a lot.
Thanks!
jimmy
21. Jul, 2009
thanks a lot
Stephan Miller
29. Aug, 2009
Thanks. I needed this. I knew how to turn it on. Just wasn’t sure where the info would be logged.
Jared Blalock
09. Dec, 2009
Thanks for the tip, this could come in handy!
ScreencastWorld
24. Feb, 2010
Thanks. I had logging enabled but needed the to know how to log additional events to the log files. Now I know – Mage::log();
Jhourlad Estrella
20. Apr, 2010
You can find the log files on your app/var/log directory. Errors generated by the system goes to exception.log and debug texts logged through Mage::log() goes to system.log
optimizacija strani
17. Jun, 2010
Im developing new module and i really need log functionality.
I set backend->Log settings->enabled: yes
System Log File Name: system.log
Logging from Mage::log(). File is located in {{base_dir}}/var/log
I created the folder, permission 777
i put Mage::log(”Log this”); in index.php AND my module…
but nothing ever logs in. What could be wrong???
Thank you very much, i really need this!
Magento Development
14. Dec, 2010
Oh great. Awesome post.Thanks for sharing.
Leave a reply