In laravel I want to change the error message and log it for 404 and 500 event. i tried for 404 event by event listener in routes.php,
Event::listen('404', function()
{
Log::write('404', 'Could not find : '.URL::full());
return Response::error('404');
});
thats working fine for me. and error message is logged with the current url. but for 500 errors, I want to log stacktrace too.. i want the log message like “500 – Uncaught Exception: ‘exception_message_and_stack_trace'”
how do I get the stacktrace string in event listener.. is it possible? sorry if I dont understand any basic things of laravel.
404 and 500 events doesn’t have much information about the errors raised them, so you can’t really do a stack trace there. They are basicly only for public messages for the users, who may hit something they shouldn’t.
For logging you should use the logger closure in your config/error.php, fill the closure with your own logging logic, it has access to the exception object.