Logger register shut down

Fatal runtime errors cause execution of the script to halt, so the registered error handler will not be called to log the error. This PR adds an option to the logger to register a shutdown function to fetch the last error. This error will be logged if it was a fatal runtime error (E_ERROR)