0

I would like to log the stacktrace of all exceptions thrown caught or uncaught.

Is there a way to do this without having to change every catch method in my application?

Thanks!

user913059
  • 579
  • 4
  • 19

3 Answers3

2

You can use set global exception handler so you will get all uncaught exceptions.

elgris
  • 516
  • 4
  • 13
0

You can use the methods from the phps base Exception class. Use getMessage to get the message Oh no! and use getTraceAsString to get a formatted trace. refer : Log caught exception with stack trace

Community
  • 1
  • 1
Tushar Gupta
  • 15,504
  • 1
  • 29
  • 47
  • But is there a way to do this globally for all exceptions thrown, I didn't want to add getTraceAsString to every one of my try catches – user913059 Aug 07 '14 at 11:33
0

You could use https://github.com/php-test-helpers/php-test-helpers to override base exceptions __construct. Just add the 'logging' logic. There is a reason why this package is called test-helpers . I don't recommend using it on production.

Anyway...it is better to rewrite your app :)

po_taka
  • 1,816
  • 17
  • 27