mac
2023-10-12 44180904ae4711ba68412b21953f66f32ef8d266
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.hdl.photovoltaic.other;
 
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) {
                if (sHdlLogLogic == null) {
                    sHdlLogLogic = new HdlLogLogic();
                }
            }
        }
        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 = "自定义输出打印信息:";
 
}