Support for logging module in backend

The Stage class has an optional argument with a filename to save
the backend logging information. All print statements are changed
to using the logging module.
Be more verbose on error/shutdown