1*90c8c64dSAndroid Build Coastguard Worker /*
2*90c8c64dSAndroid Build Coastguard Worker  * Copyright (C) 2013 The Android Open Source Project
3*90c8c64dSAndroid Build Coastguard Worker  *
4*90c8c64dSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*90c8c64dSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*90c8c64dSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*90c8c64dSAndroid Build Coastguard Worker  *
8*90c8c64dSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*90c8c64dSAndroid Build Coastguard Worker  *
10*90c8c64dSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*90c8c64dSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*90c8c64dSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*90c8c64dSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*90c8c64dSAndroid Build Coastguard Worker  * limitations under the License.
15*90c8c64dSAndroid Build Coastguard Worker  */
16*90c8c64dSAndroid Build Coastguard Worker package com.example.android.common.logger;
17*90c8c64dSAndroid Build Coastguard Worker 
18*90c8c64dSAndroid Build Coastguard Worker /**
19*90c8c64dSAndroid Build Coastguard Worker  * Helper class for a list (or tree) of LoggerNodes.
20*90c8c64dSAndroid Build Coastguard Worker  *
21*90c8c64dSAndroid Build Coastguard Worker  * <p>When this is set as the head of the list,
22*90c8c64dSAndroid Build Coastguard Worker  * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
23*90c8c64dSAndroid Build Coastguard Worker  * Most of the methods in this class server only to map a method call in Log to its equivalent
24*90c8c64dSAndroid Build Coastguard Worker  * in LogNode.</p>
25*90c8c64dSAndroid Build Coastguard Worker  */
26*90c8c64dSAndroid Build Coastguard Worker public class Log {
27*90c8c64dSAndroid Build Coastguard Worker     // Grabbing the native values from Android's native logging facilities,
28*90c8c64dSAndroid Build Coastguard Worker     // to make for easy migration and interop.
29*90c8c64dSAndroid Build Coastguard Worker     public static final int NONE = -1;
30*90c8c64dSAndroid Build Coastguard Worker     public static final int VERBOSE = android.util.Log.VERBOSE;
31*90c8c64dSAndroid Build Coastguard Worker     public static final int DEBUG = android.util.Log.DEBUG;
32*90c8c64dSAndroid Build Coastguard Worker     public static final int INFO = android.util.Log.INFO;
33*90c8c64dSAndroid Build Coastguard Worker     public static final int WARN = android.util.Log.WARN;
34*90c8c64dSAndroid Build Coastguard Worker     public static final int ERROR = android.util.Log.ERROR;
35*90c8c64dSAndroid Build Coastguard Worker     public static final int ASSERT = android.util.Log.ASSERT;
36*90c8c64dSAndroid Build Coastguard Worker 
37*90c8c64dSAndroid Build Coastguard Worker     // Stores the beginning of the LogNode topology.
38*90c8c64dSAndroid Build Coastguard Worker     private static LogNode mLogNode;
39*90c8c64dSAndroid Build Coastguard Worker 
40*90c8c64dSAndroid Build Coastguard Worker     /**
41*90c8c64dSAndroid Build Coastguard Worker      * Returns the next LogNode in the linked list.
42*90c8c64dSAndroid Build Coastguard Worker      */
getLogNode()43*90c8c64dSAndroid Build Coastguard Worker     public static LogNode getLogNode() {
44*90c8c64dSAndroid Build Coastguard Worker         return mLogNode;
45*90c8c64dSAndroid Build Coastguard Worker     }
46*90c8c64dSAndroid Build Coastguard Worker 
47*90c8c64dSAndroid Build Coastguard Worker     /**
48*90c8c64dSAndroid Build Coastguard Worker      * Sets the LogNode data will be sent to.
49*90c8c64dSAndroid Build Coastguard Worker      */
setLogNode(LogNode node)50*90c8c64dSAndroid Build Coastguard Worker     public static void setLogNode(LogNode node) {
51*90c8c64dSAndroid Build Coastguard Worker         mLogNode = node;
52*90c8c64dSAndroid Build Coastguard Worker     }
53*90c8c64dSAndroid Build Coastguard Worker 
54*90c8c64dSAndroid Build Coastguard Worker     /**
55*90c8c64dSAndroid Build Coastguard Worker      * Instructs the LogNode to print the log data provided. Other LogNodes can
56*90c8c64dSAndroid Build Coastguard Worker      * be chained to the end of the LogNode as desired.
57*90c8c64dSAndroid Build Coastguard Worker      *
58*90c8c64dSAndroid Build Coastguard Worker      * @param priority Log level of the data being logged. Verbose, Error, etc.
59*90c8c64dSAndroid Build Coastguard Worker      * @param tag Tag for for the log data. Can be used to organize log statements.
60*90c8c64dSAndroid Build Coastguard Worker      * @param msg The actual message to be logged.
61*90c8c64dSAndroid Build Coastguard Worker      * @param tr If an exception was thrown, this can be sent along for the logging facilities
62*90c8c64dSAndroid Build Coastguard Worker      *           to extract and print useful information.
63*90c8c64dSAndroid Build Coastguard Worker      */
println(int priority, String tag, String msg, Throwable tr)64*90c8c64dSAndroid Build Coastguard Worker     public static void println(int priority, String tag, String msg, Throwable tr) {
65*90c8c64dSAndroid Build Coastguard Worker         if (mLogNode != null) {
66*90c8c64dSAndroid Build Coastguard Worker             mLogNode.println(priority, tag, msg, tr);
67*90c8c64dSAndroid Build Coastguard Worker         }
68*90c8c64dSAndroid Build Coastguard Worker     }
69*90c8c64dSAndroid Build Coastguard Worker 
70*90c8c64dSAndroid Build Coastguard Worker     /**
71*90c8c64dSAndroid Build Coastguard Worker      * Instructs the LogNode to print the log data provided. Other LogNodes can
72*90c8c64dSAndroid Build Coastguard Worker      * be chained to the end of the LogNode as desired.
73*90c8c64dSAndroid Build Coastguard Worker      *
74*90c8c64dSAndroid Build Coastguard Worker      * @param priority Log level of the data being logged. Verbose, Error, etc.
75*90c8c64dSAndroid Build Coastguard Worker      * @param tag Tag for for the log data. Can be used to organize log statements.
76*90c8c64dSAndroid Build Coastguard Worker      * @param msg The actual message to be logged. The actual message to be logged.
77*90c8c64dSAndroid Build Coastguard Worker      */
println(int priority, String tag, String msg)78*90c8c64dSAndroid Build Coastguard Worker     public static void println(int priority, String tag, String msg) {
79*90c8c64dSAndroid Build Coastguard Worker         println(priority, tag, msg, null);
80*90c8c64dSAndroid Build Coastguard Worker     }
81*90c8c64dSAndroid Build Coastguard Worker 
82*90c8c64dSAndroid Build Coastguard Worker    /**
83*90c8c64dSAndroid Build Coastguard Worker      * Prints a message at VERBOSE priority.
84*90c8c64dSAndroid Build Coastguard Worker      *
85*90c8c64dSAndroid Build Coastguard Worker      * @param tag Tag for for the log data. Can be used to organize log statements.
86*90c8c64dSAndroid Build Coastguard Worker      * @param msg The actual message to be logged.
87*90c8c64dSAndroid Build Coastguard Worker      * @param tr If an exception was thrown, this can be sent along for the logging facilities
88*90c8c64dSAndroid Build Coastguard Worker      *           to extract and print useful information.
89*90c8c64dSAndroid Build Coastguard Worker      */
v(String tag, String msg, Throwable tr)90*90c8c64dSAndroid Build Coastguard Worker     public static void v(String tag, String msg, Throwable tr) {
91*90c8c64dSAndroid Build Coastguard Worker         println(VERBOSE, tag, msg, tr);
92*90c8c64dSAndroid Build Coastguard Worker     }
93*90c8c64dSAndroid Build Coastguard Worker 
94*90c8c64dSAndroid Build Coastguard Worker     /**
95*90c8c64dSAndroid Build Coastguard Worker      * Prints a message at VERBOSE priority.
96*90c8c64dSAndroid Build Coastguard Worker      *
97*90c8c64dSAndroid Build Coastguard Worker      * @param tag Tag for for the log data. Can be used to organize log statements.
98*90c8c64dSAndroid Build Coastguard Worker      * @param msg The actual message to be logged.
99*90c8c64dSAndroid Build Coastguard Worker      */
v(String tag, String msg)100*90c8c64dSAndroid Build Coastguard Worker     public static void v(String tag, String msg) {
101*90c8c64dSAndroid Build Coastguard Worker         v(tag, msg, null);
102*90c8c64dSAndroid Build Coastguard Worker     }
103*90c8c64dSAndroid Build Coastguard Worker 
104*90c8c64dSAndroid Build Coastguard Worker 
105*90c8c64dSAndroid Build Coastguard Worker     /**
106*90c8c64dSAndroid Build Coastguard Worker      * Prints a message at DEBUG priority.
107*90c8c64dSAndroid Build Coastguard Worker      *
108*90c8c64dSAndroid Build Coastguard Worker      * @param tag Tag for for the log data. Can be used to organize log statements.
109*90c8c64dSAndroid Build Coastguard Worker      * @param msg The actual message to be logged.
110*90c8c64dSAndroid Build Coastguard Worker      * @param tr If an exception was thrown, this can be sent along for the logging facilities
111*90c8c64dSAndroid Build Coastguard Worker      *           to extract and print useful information.
112*90c8c64dSAndroid Build Coastguard Worker      */
d(String tag, String msg, Throwable tr)113*90c8c64dSAndroid Build Coastguard Worker     public static void d(String tag, String msg, Throwable tr) {
114*90c8c64dSAndroid Build Coastguard Worker         println(DEBUG, tag, msg, tr);
115*90c8c64dSAndroid Build Coastguard Worker     }
116*90c8c64dSAndroid Build Coastguard Worker 
117*90c8c64dSAndroid Build Coastguard Worker     /**
118*90c8c64dSAndroid Build Coastguard Worker      * Prints a message at DEBUG priority.
119*90c8c64dSAndroid Build Coastguard Worker      *
120*90c8c64dSAndroid Build Coastguard Worker      * @param tag Tag for for the log data. Can be used to organize log statements.
121*90c8c64dSAndroid Build Coastguard Worker      * @param msg The actual message to be logged.
122*90c8c64dSAndroid Build Coastguard Worker      */
d(String tag, String msg)123*90c8c64dSAndroid Build Coastguard Worker     public static void d(String tag, String msg) {
124*90c8c64dSAndroid Build Coastguard Worker         d(tag, msg, null);
125*90c8c64dSAndroid Build Coastguard Worker     }
126*90c8c64dSAndroid Build Coastguard Worker 
127*90c8c64dSAndroid Build Coastguard Worker     /**
128*90c8c64dSAndroid Build Coastguard Worker      * Prints a message at INFO priority.
129*90c8c64dSAndroid Build Coastguard Worker      *
130*90c8c64dSAndroid Build Coastguard Worker      * @param tag Tag for for the log data. Can be used to organize log statements.
131*90c8c64dSAndroid Build Coastguard Worker      * @param msg The actual message to be logged.
132*90c8c64dSAndroid Build Coastguard Worker      * @param tr If an exception was thrown, this can be sent along for the logging facilities
133*90c8c64dSAndroid Build Coastguard Worker      *           to extract and print useful information.
134*90c8c64dSAndroid Build Coastguard Worker      */
i(String tag, String msg, Throwable tr)135*90c8c64dSAndroid Build Coastguard Worker     public static void i(String tag, String msg, Throwable tr) {
136*90c8c64dSAndroid Build Coastguard Worker         println(INFO, tag, msg, tr);
137*90c8c64dSAndroid Build Coastguard Worker     }
138*90c8c64dSAndroid Build Coastguard Worker 
139*90c8c64dSAndroid Build Coastguard Worker     /**
140*90c8c64dSAndroid Build Coastguard Worker      * Prints a message at INFO priority.
141*90c8c64dSAndroid Build Coastguard Worker      *
142*90c8c64dSAndroid Build Coastguard Worker      * @param tag Tag for for the log data. Can be used to organize log statements.
143*90c8c64dSAndroid Build Coastguard Worker      * @param msg The actual message to be logged.
144*90c8c64dSAndroid Build Coastguard Worker      */
i(String tag, String msg)145*90c8c64dSAndroid Build Coastguard Worker     public static void i(String tag, String msg) {
146*90c8c64dSAndroid Build Coastguard Worker         i(tag, msg, null);
147*90c8c64dSAndroid Build Coastguard Worker     }
148*90c8c64dSAndroid Build Coastguard Worker 
149*90c8c64dSAndroid Build Coastguard Worker     /**
150*90c8c64dSAndroid Build Coastguard Worker      * Prints a message at WARN priority.
151*90c8c64dSAndroid Build Coastguard Worker      *
152*90c8c64dSAndroid Build Coastguard Worker      * @param tag Tag for for the log data. Can be used to organize log statements.
153*90c8c64dSAndroid Build Coastguard Worker      * @param msg The actual message to be logged.
154*90c8c64dSAndroid Build Coastguard Worker      * @param tr If an exception was thrown, this can be sent along for the logging facilities
155*90c8c64dSAndroid Build Coastguard Worker      *           to extract and print useful information.
156*90c8c64dSAndroid Build Coastguard Worker      */
w(String tag, String msg, Throwable tr)157*90c8c64dSAndroid Build Coastguard Worker     public static void w(String tag, String msg, Throwable tr) {
158*90c8c64dSAndroid Build Coastguard Worker         println(WARN, tag, msg, tr);
159*90c8c64dSAndroid Build Coastguard Worker     }
160*90c8c64dSAndroid Build Coastguard Worker 
161*90c8c64dSAndroid Build Coastguard Worker     /**
162*90c8c64dSAndroid Build Coastguard Worker      * Prints a message at WARN priority.
163*90c8c64dSAndroid Build Coastguard Worker      *
164*90c8c64dSAndroid Build Coastguard Worker      * @param tag Tag for for the log data. Can be used to organize log statements.
165*90c8c64dSAndroid Build Coastguard Worker      * @param msg The actual message to be logged.
166*90c8c64dSAndroid Build Coastguard Worker      */
w(String tag, String msg)167*90c8c64dSAndroid Build Coastguard Worker     public static void w(String tag, String msg) {
168*90c8c64dSAndroid Build Coastguard Worker         w(tag, msg, null);
169*90c8c64dSAndroid Build Coastguard Worker     }
170*90c8c64dSAndroid Build Coastguard Worker 
171*90c8c64dSAndroid Build Coastguard Worker     /**
172*90c8c64dSAndroid Build Coastguard Worker      * Prints a message at WARN priority.
173*90c8c64dSAndroid Build Coastguard Worker      *
174*90c8c64dSAndroid Build Coastguard Worker      * @param tag Tag for for the log data. Can be used to organize log statements.
175*90c8c64dSAndroid Build Coastguard Worker      * @param tr If an exception was thrown, this can be sent along for the logging facilities
176*90c8c64dSAndroid Build Coastguard Worker      *           to extract and print useful information.
177*90c8c64dSAndroid Build Coastguard Worker      */
w(String tag, Throwable tr)178*90c8c64dSAndroid Build Coastguard Worker     public static void w(String tag, Throwable tr) {
179*90c8c64dSAndroid Build Coastguard Worker         w(tag, null, tr);
180*90c8c64dSAndroid Build Coastguard Worker     }
181*90c8c64dSAndroid Build Coastguard Worker 
182*90c8c64dSAndroid Build Coastguard Worker     /**
183*90c8c64dSAndroid Build Coastguard Worker      * Prints a message at ERROR priority.
184*90c8c64dSAndroid Build Coastguard Worker      *
185*90c8c64dSAndroid Build Coastguard Worker      * @param tag Tag for for the log data. Can be used to organize log statements.
186*90c8c64dSAndroid Build Coastguard Worker      * @param msg The actual message to be logged.
187*90c8c64dSAndroid Build Coastguard Worker      * @param tr If an exception was thrown, this can be sent along for the logging facilities
188*90c8c64dSAndroid Build Coastguard Worker      *           to extract and print useful information.
189*90c8c64dSAndroid Build Coastguard Worker      */
e(String tag, String msg, Throwable tr)190*90c8c64dSAndroid Build Coastguard Worker     public static void e(String tag, String msg, Throwable tr) {
191*90c8c64dSAndroid Build Coastguard Worker         println(ERROR, tag, msg, tr);
192*90c8c64dSAndroid Build Coastguard Worker     }
193*90c8c64dSAndroid Build Coastguard Worker 
194*90c8c64dSAndroid Build Coastguard Worker     /**
195*90c8c64dSAndroid Build Coastguard Worker      * Prints a message at ERROR priority.
196*90c8c64dSAndroid Build Coastguard Worker      *
197*90c8c64dSAndroid Build Coastguard Worker      * @param tag Tag for for the log data. Can be used to organize log statements.
198*90c8c64dSAndroid Build Coastguard Worker      * @param msg The actual message to be logged.
199*90c8c64dSAndroid Build Coastguard Worker      */
e(String tag, String msg)200*90c8c64dSAndroid Build Coastguard Worker     public static void e(String tag, String msg) {
201*90c8c64dSAndroid Build Coastguard Worker         e(tag, msg, null);
202*90c8c64dSAndroid Build Coastguard Worker     }
203*90c8c64dSAndroid Build Coastguard Worker 
204*90c8c64dSAndroid Build Coastguard Worker     /**
205*90c8c64dSAndroid Build Coastguard Worker      * Prints a message at ASSERT priority.
206*90c8c64dSAndroid Build Coastguard Worker      *
207*90c8c64dSAndroid Build Coastguard Worker      * @param tag Tag for for the log data. Can be used to organize log statements.
208*90c8c64dSAndroid Build Coastguard Worker      * @param msg The actual message to be logged.
209*90c8c64dSAndroid Build Coastguard Worker      * @param tr If an exception was thrown, this can be sent along for the logging facilities
210*90c8c64dSAndroid Build Coastguard Worker      *           to extract and print useful information.
211*90c8c64dSAndroid Build Coastguard Worker      */
wtf(String tag, String msg, Throwable tr)212*90c8c64dSAndroid Build Coastguard Worker     public static void wtf(String tag, String msg, Throwable tr) {
213*90c8c64dSAndroid Build Coastguard Worker         println(ASSERT, tag, msg, tr);
214*90c8c64dSAndroid Build Coastguard Worker     }
215*90c8c64dSAndroid Build Coastguard Worker 
216*90c8c64dSAndroid Build Coastguard Worker     /**
217*90c8c64dSAndroid Build Coastguard Worker      * Prints a message at ASSERT priority.
218*90c8c64dSAndroid Build Coastguard Worker      *
219*90c8c64dSAndroid Build Coastguard Worker      * @param tag Tag for for the log data. Can be used to organize log statements.
220*90c8c64dSAndroid Build Coastguard Worker      * @param msg The actual message to be logged.
221*90c8c64dSAndroid Build Coastguard Worker      */
wtf(String tag, String msg)222*90c8c64dSAndroid Build Coastguard Worker     public static void wtf(String tag, String msg) {
223*90c8c64dSAndroid Build Coastguard Worker         wtf(tag, msg, null);
224*90c8c64dSAndroid Build Coastguard Worker     }
225*90c8c64dSAndroid Build Coastguard Worker 
226*90c8c64dSAndroid Build Coastguard Worker     /**
227*90c8c64dSAndroid Build Coastguard Worker      * Prints a message at ASSERT priority.
228*90c8c64dSAndroid Build Coastguard Worker      *
229*90c8c64dSAndroid Build Coastguard Worker      * @param tag Tag for for the log data. Can be used to organize log statements.
230*90c8c64dSAndroid Build Coastguard Worker      * @param tr If an exception was thrown, this can be sent along for the logging facilities
231*90c8c64dSAndroid Build Coastguard Worker      *           to extract and print useful information.
232*90c8c64dSAndroid Build Coastguard Worker      */
wtf(String tag, Throwable tr)233*90c8c64dSAndroid Build Coastguard Worker     public static void wtf(String tag, Throwable tr) {
234*90c8c64dSAndroid Build Coastguard Worker         wtf(tag, null, tr);
235*90c8c64dSAndroid Build Coastguard Worker     }
236*90c8c64dSAndroid Build Coastguard Worker }
237