aboutsummaryrefslogtreecommitdiff
path: root/app/src/test/kotlin/android/util/Log.java
blob: a2f431edd1e5f183298eeab1ff300c96963d6f84 (plain)
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
package android.util;

import java.util.Locale;

/**
 * Created by Allan Wang on 31/12/17.
 */
public class Log {

    /**
     * Priority constant for the println method; use Log.v.
     */
    public static final int VERBOSE = 2;

    /**
     * Priority constant for the println method; use Log.d.
     */
    public static final int DEBUG = 3;

    /**
     * Priority constant for the println method; use Log.i.
     */
    public static final int INFO = 4;

    /**
     * Priority constant for the println method; use Log.e.
     */
    public static final int ERROR = 6;

    public static int e(String tag, String msg, Throwable t) {
        System.err.println("ERROR: " + tag + ": " + msg + "\n\tThrowable: " + t.getMessage());
        return 0;
    }

    public static int println(int priority, String tag, String msg) {
        switch (priority) {
            case VERBOSE:
                p("V", tag, msg);
                break;
            case INFO:
                p("I", tag, msg);
                break;
            case DEBUG:
                p("D", tag, msg);
                break;
            case ERROR:
                p("E", tag, msg);
                break;
            default:
                p("L " + priority, tag, msg);
                break;
        }
        return 0;
    }

    private static void p(String flag, String tag, String msg) {
        System.out.println(String.format(Locale.CANADA, "%s: %s: %s", flag, tag, msg));
    }

}