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
  • 539
  • 4
  • 18

3 Answers3

2

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

elgris
  • 478
  • 3
  • 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
  • 13,804
  • 1
  • 24
  • 44
  • 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,766
  • 16
  • 27