lmw
2023-06-13 4b7d8d9a038f6522df46d0f14fa07eb940a1b34d
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
package com.kuanzhai.driver.utils;
 
import android.util.Log;
 
// http://www.jianshu.com/p/325e8f025c98
public class LogUtils {
 
    public static final String TAG = "xld.";
 
    public static final int VERBOSE = 1;
 
    public static final int DEBUG = 2;
 
    public static final int INFO = 3;
 
    public static final int WARN = 4;
 
    public static final int ERROR = 5;
 
    public static final int NOTHING = 6;
 
    public static final int LEVEL = VERBOSE;
 
    private static boolean IsOpenLog;
 
    public static void OpenLog(boolean isOpen) {
        if (isOpen) {
            IsOpenLog = true;
        } else {
            IsOpenLog = false;
        }
    }
 
    public static void v(String target, String msg) {
        if (LEVEL <= VERBOSE && IsOpenLog) {
            Log.v(TAG + target, msg);
        }
    }
 
    public static void d(String target, String msg) {
        if (LEVEL <= DEBUG && IsOpenLog) {
            Log.d(TAG + target, msg);
        }
    }
 
    public static void d(String msg) {
        if (LEVEL <= DEBUG && IsOpenLog) {
            Log.d(TAG, msg);
        }
    }
 
    public static void i(String target, String msg) {
        if (LEVEL <= INFO && IsOpenLog) {
            Log.i(TAG + target, msg);
        }
    }
 
    public static void w(String target, String msg) {
        if (LEVEL <= WARN && IsOpenLog) {
            Log.w(TAG + target, msg);
        }
    }
 
    public static void e(String target, String msg) {
 
        if (target == null || target.length() == 0 || !IsOpenLog)
            return;
 
        int segmentSize = 3 * 1024;
        long length = msg.length();
        if (length <= segmentSize) {// 长度小于等于限制直接打印
            Log.e(TAG + target, msg);
        } else {
            while (msg.length() > segmentSize) {// 循环分段打印日志
                String logContent = msg.substring(0, segmentSize);
                msg = msg.replace(logContent, "");
                Log.e(TAG + target, logContent);
            }
            Log.e(TAG + target, msg);// 打印剩余日志
        }
    }
 
    public static void e(String msg) {
        if (!IsOpenLog)
            return;
 
        int segmentSize = 3 * 1024;
        long length = msg.length();
        if (length <= segmentSize) {// 长度小于等于限制直接打印
            Log.e(TAG, msg);
        } else {
            while (msg.length() > segmentSize) {// 循环分段打印日志
                String logContent = msg.substring(0, segmentSize);
                msg = msg.replace(logContent, "");
                Log.e(TAG, logContent);
            }
            Log.e(TAG, msg);// 打印剩余日志
        }
    }
 
}