测试博客

JAVA学习网 2018-10-26 12:21:02

测试

测试

慈恩寺

试试啊

package com.didapinche.rs.phoenix.util;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Map;

@Slf4j
public class LoggerUtil {

    private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS Z");

    public enum LOG_CATEGORY{
        SELF, OTHERS, FOREIGN
    }

    public enum INVOKE_SOURCES{
        WEB, SOAP, REST, THRIFT
    }


    /**
     * @param log_category  调用分类,自身接口:SELF 外部服务:FOREIGN
     * @param type          调用种类[WEB,SOAP,REST,THRIFT]
     * @param svcName       服务名
     * @param interfaceName 接口名
     * @param method        方法名
     * @param args          入参
     * @param duration      时间开销
     */
    public static void info(LOG_CATEGORY log_category, INVOKE_SOURCES type, String svcName, String interfaceName, String method, Map<String, Object> args, long duration){
        if(args == null || args.isEmpty()){
            log.info("{} - {} - {} - {} - {}", type, svcName, interfaceName, method, duration);
        } else {
            log.info("{} - {} - {} - {} - {} - {}", type, svcName, interfaceName, method, JSON.toJSONString(args), duration);
        }
    }


    /**
     * @param log_category  调用分类,自身接口:SELF 外部服务:FOREIGN
     * @param type          调用种类[WEB,SOAP,REST,THRIFT]
     * @param svcName       服务名
     * @param interfaceName 接口名
     * @param method        方法名
     * @param args          入参
     * @param ex          错误信息
     */
    public static void error(LOG_CATEGORY log_category, INVOKE_SOURCES type, String svcName, String interfaceName, String method, Map<String, Object> args, Exception ex){
        if(args == null || args.isEmpty()){
            log.error("{} - {} - {} - {} - {}", type, svcName, interfaceName, method, ex);
        } else {
            log.error("{} - {} - {} - {} - {} - {}", type, svcName, interfaceName, method, JSON.toJSONString(args), ex);
        }
    }
}
阅读(2309) 评论(0)