aboutsummaryrefslogtreecommitdiffstats
path: root/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/Logging.java
blob: 6af7a70e7666e8f4fea0a7cce7e36a2bacc1c4e4 (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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package de.thedevstack.android.logcat;

import android.util.Log;

/**
 * Utility class to prefix every log tag.
 * This can be used for better filtering in the log cat output activity.
 */
public class Logging {
    /**
     * The prefix for every log tag.
     */
    protected static String LOG_TAG_PREFIX = "thedevstack.";

    /**
     * Changes the default log tag prefix.
     * The default value is <code>thedevstack.</code>
     * @param logTagPrefix the new log tag prefix to use
     */
    public static void initLogTagPrefix(String logTagPrefix) {
        if (null != logTagPrefix) {
            LOG_TAG_PREFIX = logTagPrefix;
        }
    }

    /**
     * Returns the current log tag prefix.
     * @return value of Logging.LOG_TAG_PREFIX
     */
    public static String getLogTagPrefix() {
        return LOG_TAG_PREFIX;
    }

    /**
     * Send a {@link Log#VERBOSE} log message.
     * @param tag Used to identify the source of a log message.  It usually identifies
     *        the class or activity where the log call occurs.
     * @param msg The message you would like logged.
     */
    public static int v(String tag, String msg) {
        return Log.v(Logging.LOG_TAG_PREFIX + tag, msg);
    }

    /**
     * Send a {@link Log#VERBOSE} log message and log the exception.
     * @param tag Used to identify the source of a log message.  It usually identifies
     *        the class or activity where the log call occurs.
     * @param msg The message you would like logged.
     * @param tr An exception to log
     */
    public static int v(String tag, String msg, Throwable tr) {
        return Log.v(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr));
    }

    /**
     * Send a {@link Log#DEBUG} log message.
     * @param tag Used to identify the source of a log message.  It usually identifies
     *        the class or activity where the log call occurs.
     * @param msg The message you would like logged.
     */
    public static int d(String tag, String msg) {
        return Log.d(Logging.LOG_TAG_PREFIX + tag, msg);
    }

    /**
     * Send a {@link Log#DEBUG} log message and log the exception.
     * @param tag Used to identify the source of a log message.  It usually identifies
     *        the class or activity where the log call occurs.
     * @param msg The message you would like logged.
     * @param tr An exception to log
     */
    public static int d(String tag, String msg, Throwable tr) {
        return Log.d(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr));
    }

    /**
     * Send an {@link Log#INFO} log message.
     * @param tag Used to identify the source of a log message.  It usually identifies
     *        the class or activity where the log call occurs.
     * @param msg The message you would like logged.
     */
    public static int i(String tag, String msg) {
        return Log.i(Logging.LOG_TAG_PREFIX + tag, msg);
    }

    /**
     * Send a {@link Log#INFO} log message and log the exception.
     * @param tag Used to identify the source of a log message.  It usually identifies
     *        the class or activity where the log call occurs.
     * @param msg The message you would like logged.
     * @param tr An exception to log
     */
    public static int i(String tag, String msg, Throwable tr) {
        return Log.i(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr));
    }

    /**
     * Send a {@link Log#WARN} log message.
     * @param tag Used to identify the source of a log message.  It usually identifies
     *        the class or activity where the log call occurs.
     * @param msg The message you would like logged.
     */
    public static int w(String tag, String msg) {
        return Log.w(Logging.LOG_TAG_PREFIX + tag, msg);
    }

    /**
     * Send a {@link Log#WARN} log message and log the exception.
     * @param tag Used to identify the source of a log message.  It usually identifies
     *        the class or activity where the log call occurs.
     * @param msg The message you would like logged.
     * @param tr An exception to log
     */
    public static int w(String tag, String msg, Throwable tr) {
        return Log.w(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr));
    }

    /*
     * Send a {@link #WARN} log message and log the exception.
     * @param tag Used to identify the source of a log message.  It usually identifies
     *        the class or activity where the log call occurs.
     * @param tr An exception to log
     */
    public static int w(String tag, Throwable tr) {
        return Log.w(Logging.LOG_TAG_PREFIX + tag, Log.getStackTraceString(tr));
    }

    /**
     * Send an {@link Log#ERROR} log message.
     * @param tag Used to identify the source of a log message.  It usually identifies
     *        the class or activity where the log call occurs.
     * @param msg The message you would like logged.
     */
    public static int e(String tag, String msg) {
        return Log.e(Logging.LOG_TAG_PREFIX + tag, msg);
    }

    /**
     * Send a {@link Log#ERROR} log message and log the exception.
     * @param tag Used to identify the source of a log message.  It usually identifies
     *        the class or activity where the log call occurs.
     * @param msg The message you would like logged.
     * @param tr An exception to log
     */
    public static int e(String tag, String msg, Throwable tr) {
        return Log.e(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr));
    }
}