add write_error_log function

write_error_log:
  print error log to stderr when unexpected connection errors occured.