phpdebugginglogging

debug_print_backtrace() to String for log-file


I have a problem. I would like to log the backtrace in a specific case in a log-file. debug_print_backtrace() builds a correct string for my purposes but debug_print_backtrace() prints the trace on the screen instead of returning it.


Solution

  • Use another function. debug_backtrace() returns an array that you can loop through, format and save:

    $data = debug_backtrace();
    

    Or use output buffering for the formatted output string:

    ob_start();
    debug_print_backtrace();
    $data = ob_get_clean();