package com.tzld.piaoquan.recommend.server.common;


import com.aliyun.openservices.aliyun.log.producer.Callback;
import com.aliyun.openservices.aliyun.log.producer.Result;
import com.aliyun.openservices.log.common.LogItem;

import java.util.List;

/**
 * @author dyp
 */
public class RecommendLoghubAppenderCallback<E> implements Callback {
    protected RecommendLoghubAppender<E> loghubAppender;
    protected String project;
    protected String logstore;
    protected String topic;
    protected String source;
    protected List<LogItem> logItems;

    public RecommendLoghubAppenderCallback(RecommendLoghubAppender<E> loghubAppender, String project, String logstore,
                                           String topic, String source, List<LogItem> logItems) {
        this.loghubAppender = loghubAppender;
        this.project = project;
        this.logstore = logstore;
        this.topic = topic;
        this.source = source;
        this.logItems = logItems;
    }

    public void onCompletion(Result result) {
        if (!result.isSuccessful()) {
            this.loghubAppender.addError("Failed to send log, project=" + this.project + ", logStore=" + this.logstore + ", topic=" + this.topic + ", source=" + this.source + ", logItem=" + this.logItems + ", errorCode=" + result.getErrorCode() + ", errorMessage=" + result.getErrorMessage());
        }

    }
}
