Better error logging

Fixed the error logging mechanism to be simpler and to properly return
a non-zero exit code.