debug_print_backtrace() to String for log-file

前端 未结 3 1482
一向
一向 2021-02-12 12:48

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 debu

3条回答
  •  悲哀的现实
    2021-02-12 13:40

    It's possible to do it with even less code, actually. Avoid the overhead of buffering with...

    $error_string = (new Exception)->getTraceAsString();
    

    That gives you the exact same output as debug_print_backtrace() stored to the $error_string.

    And if you want to get more information for a more valuable stacktrace (line numbers, local object vars, etc.), try...

    $error_string = print_r($e->getTrace(), true);
    

提交回复
热议问题