Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save the result of Whoops PrettyPageHandler

Tags:

php

whoops

I'm using the Whoops error library (and loving it) on dev to show the PrettyPageHandler like so:

if (ENVIRONMENT == 'local') {
    $whoops = new \Whoops\Run;
    $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
    $whoops->register();
}

For live I'm using the CallbackHandler to show the end user a "user friendly" error message.

Is there anyway to save the result/output of PrettyPageHandler into a database or even to the filesystem? My thinking is to show the end user the friendly error page but record the error at the same time using the PrettyPageHandler to look back at and debug the error the user got.

like image 836
twigg Avatar asked Apr 24 '17 13:04

twigg


1 Answers

Like described in the documentation:

$run->pushHandler(function($exception, $inspector, $run) {
    var_dump($exception->getMessage());
    return Handler::DONE;
});

replace var_dump($exception->getMessage()); with your custom code to save to database or file log.

https://github.com/filp/whoops/blob/master/docs/API%20Documentation.md#core-handlers-1

Edit1:

To use the PrettyPageHandler to save the log, create a custom handler extending from PrettyPageHandler, and in the place where the handle return the formated response before return the response to the user, save in database or filesytem in desired format.

like image 92
rafrsr Avatar answered Oct 22 '22 09:10

rafrsr