Improved logging of rare errors.

It was hard to detect which hook or module caused the server's shutdown.
This commit adds this kind of information.