private void log(Exception exception) {
    if (ctx.channel().isActive()) {
      String uri = "unknown";
      RestMethod restMethod = RestMethod.UNKNOWN;
      if (request != null) {
        uri = request.getUri();
        restMethod = request.getRestMethod();
      }
      if (exception instanceof RestServiceException) {
        RestServiceErrorCode errorCode = ((RestServiceException) exception).getErrorCode();
        ResponseStatus responseStatus = ResponseStatus.getResponseStatus(errorCode);
        if (responseStatus == ResponseStatus.InternalServerError) {
          logger.error("Internal error handling request {} with method {}", uri, restMethod, exception);
        } else {
          logger.trace("Error handling request {} with method {}", uri, restMethod, exception);
        }
      } else if (Utils.isPossibleClientTermination(exception)) {
        logger.trace("Client likely terminated connection while handling request {} with method {}", uri, restMethod,
            exception);
      } else {
        logger.error("Unexpected error handling request {} with method {}", uri, restMethod, exception);
      }
    } else {
      logger.debug("Exception encountered after channel {} became inactive", ctx.channel(), exception);
    }
  }
Logs the exception at the appropriate level.
@param exception the {@link Exception} that has to be logged.
ambry-rest/src/main/java/com/github/ambry/rest/NettyResponseChannel.java