private void logTask(HostRoleCommandEntity commandEntity, Long requestId, HostRoleStatus lastTaskStatus) {

    RequestDetails.Component component = new RequestDetails.Component(commandEntity.getRole(), commandEntity.getHostName());
    RequestDetails details = auditlogRequestCache.getIfPresent(requestId);
    if(details == null) {
      return;
    }

    HostRoleStatus cachedStatus = details.getTasks().get(component);

    if(lastTaskStatus == null || cachedStatus != lastTaskStatus ) {
      AuditEvent taskEvent = TaskStatusAuditEvent.builder()
        .withTaskId(String.valueOf(commandEntity.getTaskId()))
        .withHostName(commandEntity.getHostName())
        .withUserName(details.getUserName())
        .withProxyUserName(details.getProxyUserName())
        .withOperation(commandEntity.getRoleCommand() + " " + commandEntity.getRole())
        .withDetails(commandEntity.getCommandDetail())
        .withStatus(commandEntity.getStatus().toString())
        .withRequestId(String.valueOf(requestId))
        .withTimestamp(System.currentTimeMillis())
        .build();

      auditLogger.log(taskEvent);
    }
  }
Logs task status change
@param commandEntity
@param requestId
@param lastTaskStatus
ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java