Enhanced error logging