Generic error logging utility