Cperello/log stacktraces

I tried to add a unit test for this change, but I'm not able to get the backtrace inside the unittest...