package com.hh.arome.http;


import android.text.TextUtils;
import android.util.Log;


import com.hh.arome.utlis.log.AppLogUtils;
import com.hh.arome.utlis.log.LogType;

import okhttp3.logging.HttpLoggingInterceptor;

import static com.hh.arome.common.Constants.LogcatValue.LINE;
import static com.hh.arome.common.Constants.LogcatValue.NODE;
import static com.hh.arome.common.Constants.LogcatValue.WARP;

public class HttpLogger implements HttpLoggingInterceptor.Logger {
    @Override
    public void log(String log) {
        Log.i("http",log);
        if(!TextUtils.isEmpty(log)){
            filterSaveLog(log);
        }
    }

    // 过滤指定的日志
    private void filterSaveLog(String log) {
        if (log.startsWith("Date")
                || log.startsWith("Content")
                || log.startsWith("Transfer-Encoding")
                || log.startsWith("Connection")
                || log.startsWith("Expires")
                || log.startsWith("Server")
                || log.startsWith("Vary")
                || log.startsWith("uid")
                || log.startsWith("Cdn-Time")
                || log.startsWith("Dtk-Code")
                || log.startsWith("Upstream-Name")
                || log.startsWith("Access")
                || log.startsWith("backend")
                || log.startsWith("Cache-Control")
                || log.startsWith("X-Ser")
                || log.startsWith("--> END")
                || log.startsWith("<-- END")
                || log.startsWith("X-Cache")) {
            return;
        }

        // 开始保存日志-网络
        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                .append("网络请求").append(WARP)
                .append(log)
                .toString()
        );

    }
}
