Claudiu Persoiu

Blog-ul lui Claudiu Persoiu

Magento native stack trace

with 5 comments

There are moments when you need to see the stack trace, to know how a certain point was reached. There are two native functions for that in PHP: debug_backtrace() si debug_print_backtrace. The first one returns an array and the second will print the stack trace to the screen.

The problem is that this functions must be customized for Magento, because it is very possible that when you’re running debug_backtrace()  you can run out of memory before you can send the output to a log file.

Magento has a native function for that purpose: Varien_Debug::backtrace([bool $return = false], [bool $html = true], [bool $withArgs = true]). In order to send the resulting stacktrace to a log file you simply all it with:

Mage::log(Varien_Debug::backtrace(true, false));

This technique is very useful when you need to see where an certain object is initialized, and what methods were executed up to that point.

Written by Claudiu Persoiu

25 February 2012 at 11:48 AM

Posted in Magento,PHP

Tagged with , , ,

5 Responses to 'Magento native stack trace'

Subscribe to comments with RSS or TrackBack to 'Magento native stack trace'.

  1. Salut,

    Iti citesc cu mare interes post-urile si chiar daca nu te cunosc personal te apreciez pentru cunostintele pe care le ai in domeniu; dar e pacat sa dai cu bata-n limba romana, mai ales ca gramatica este cu mult mai usoara decat tehnologiile cu care lucram zilnic. “Numai tu știi ce s-a întâmplat.”
    Sunt sigur ca a fost doar o mica scapare 🙂

    Tinand cont ca este o critica constructiva sunt sigur ca nu te va deranja.

    Numai bine,


    25 February 2012 at 2:35 PM

  2. Salut,

    Multumesc pentru critica constructiva. Mi-a scapat si am observat doar dupa ce l-am publicat. 🙂



    26 February 2012 at 1:29 PM

  3. La tine nu e trunchiat outputul de la ::backtrace ? La mine e, si nu-mi place.


    22 March 2012 at 1:11 PM

  4. Cred ca tine mai mult de ce ai nevoie, pe mine nu m-a deranjat pana acum.


    22 March 2012 at 2:45 PM

  5. Truncherea este necesara pentru ca parametrii uneori sunt foarte mari. Pentru a modifica marimea string-ului trunchiat poti apela inainte de linia in discutie:

    Varien_Debug::$argLength = $marimeaDorita;

    Claudiu Persoiu

    23 May 2014 at 6:04 PM

Leave a Reply