lmw
2023-03-11 4df5bb59e5fe9f9d140e5610f7772dd8a05a28d4
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
package com.beloo.widget.chipslayoutmanager.util.log;
 
import com.beloo.widget.chipslayoutmanager.BuildConfig;
 
import java.util.HashSet;
import java.util.Set;
 
/** this class with static methods created only for fast replace of default android log */
public class Log {
 
    private static LogSwitcher logSwitcher = new LogSwitcher();
 
    @SuppressWarnings("ConstantConditions")
    private static LogWrapper log = BuildConfig.isLogEnabled ? new AndroidLog() : new SilentLog();
 
    ///////////////////////////////////////////////////////////////////////////
    // default android log delegates
    ///////////////////////////////////////////////////////////////////////////
 
    @SuppressWarnings("WeakerAccess")
    public static int d (String tag, String msg) {
        return log.d(tag, msg);
    }
 
    @SuppressWarnings("WeakerAccess")
    public static int v (String tag, String msg) {
        return log.v(tag, msg);
    }
 
    @SuppressWarnings("WeakerAccess")
    public static int w (String tag, String msg) {
        return log.w(tag, msg);
    }
 
    @SuppressWarnings("WeakerAccess")
    public static int i (String tag, String msg) {
        return log.i(tag, msg);
    }
 
    public static int e (String tag, String msg) {
        return log.e(tag, msg);
    }
 
    ///////////////////////////////////////////////////////////////////////////
    // android log delegates with switcher
    ///////////////////////////////////////////////////////////////////////////
 
    @SuppressWarnings("WeakerAccess")
    public static int d (String tag, String msg, int logCode) {
        return logSwitcher.isEnabled(logCode) ? d(tag, msg) : 0;
    }
 
    @SuppressWarnings("WeakerAccess")
    public static int v (String tag, String msg, int logCode) {
        return logSwitcher.isEnabled(logCode) ? v(tag, msg) : 0;
    }
 
    @SuppressWarnings("WeakerAccess")
    public static int w (String tag, String msg, int logCode) {
        return logSwitcher.isEnabled(logCode) ? w(tag, msg) : 0;
    }
 
    @SuppressWarnings("WeakerAccess")
    public static int i (String tag, String msg, int logCode) {
        return logSwitcher.isEnabled(logCode) ? i(tag, msg) : 0;
    }
 
    public static void with(LogSwitcher logSwitcher) {
        Log.logSwitcher = logSwitcher;
    }
 
    public static class LogSwitcher {
        private Set<Integer> enabledLogs = new HashSet<>();
 
        boolean isEnabled(int logCode) {
            return enabledLogs.contains(logCode);
        }
 
        public LogSwitcher with(int logCode) {
            enabledLogs.add(logCode);
            return this;
        }
 
        public LogSwitcher without(int logCode) {
            enabledLogs.remove(logCode);
            return this;
        }
    }
}