Added function to log error events