package  org.ts.ddcs.log;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class LogHelper {

    public static Logger logger= LoggerFactory.getLogger(LogHelper.class);
    public static void error(Exception e){
        logger.error("[ERROR]",e.fillInStackTrace());
    }
    public static void error(String logid,Exception e){
        logger.error(logid+" [ERROR] ",e.fillInStackTrace());
    }
    public static void error(String error){
        logger.error(error);
    }

    public static void info(String info, Object... objects){
        logger.info(info, objects);
    }

    public static void debug(String debug){
        logger.debug(debug);
    }

    public static String createLogId(String prefix){
        try {
            SimpleDateFormat timeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
            String time = timeFormat.format(new Date());
            Random rm = new Random();
            // 获得随机数
            double pross = (1 + rm.nextDouble()) * Math.pow(10, 5);
            // 将获得的获得随机数转化为字符串
            String fixLengthString = String.valueOf(pross);
            // 返回固定的长度的随机数
            String ranom = fixLengthString.substring(1, 6);
            return prefix + "_" + time + "_" + ranom;
        }catch (Exception e){
            LogHelper.error(e);
            return prefix;
        }
    }
}
