Cleanup debug and error output.

A few more stray sprintf()s have been changed to logging methods.