mac
2023-10-13 c13cb54d0b9f9b2c73f213b6cdb163f462fd64c7
app/src/main/java/com/hdl/photovoltaic/other/HdlLogLogic.java
@@ -2,13 +2,26 @@
import android.util.Log;
import com.google.gson.Gson;
/**
 * 日志逻辑
 */
public class HdlLogLogic {
    /**
     * 是否需要打印(true不需要打印)
     */
    public static boolean isDebug = false;
    private static volatile HdlLogLogic sHdlLogLogic;
    /**
     * 获取当前对象
     *
     * @return HdlLogLogic
     */
    public static synchronized HdlLogLogic getInstance() {
        if (sHdlLogLogic == null) {
            synchronized (HdlLogLogic.class) {
@@ -20,11 +33,85 @@
        return sHdlLogLogic;
    }
    /**
     * android打印
     *
     * @param tag 标签
     * @param mgs 错误信息
     */
    public static void print(String tag, String mgs) {
        if (isDebug) {
            return;
        }
        Log.d(tag, mgs);
    }
    /**
     * java打印
     *
     * @param mgs 输出信息
     */
    public static void print(String mgs) {
        if (isDebug) {
            return;
        }
        System.out.println(mgs);
    }
    /**
     * java打印
     *
     * @param tag  标题
     * @param mgs  错误信息
     * @param code 错误码
     */
    public static void print(String tag, String mgs, int code) {
        if (isDebug) {
            return;
        }
//        StringBuilder b = new StringBuilder();
//        b.append(title);
//        b.append(tag);
//        b.
        System.out.println(title + tag + "======" + mgs + "(" + code + ")");
    }
    /**
     * java打印
     *
     * @param tag  标题
     * @param mgs  错误信息
     * @param code 错误码
     */
    public static void print(String tag, String mgs, String code) {
        if (isDebug) {
            return;
        }
        System.out.println(title + tag + "======" + mgs + "(" + code + ")");
    }
    /**
     * java打印
     *
     * @param tag 标题
     * @param o   错误信息
     */
    public static void print(String tag, Object o) {
        if (isDebug) {
            return;
        }
        if (o == null) {
            System.out.println(title + tag);
        } else {
            try {
                System.out.println(title + tag + "======" + new Gson().toJson(o));
            } catch (Exception e) {
                System.out.println(title + tag + "======" + e.getMessage());
            }
        }
    }
    private static final String title = "自定义输出打印信息:";
}