1111import java .util .NoSuchElementException ;
1212
1313/**
14- * simple wrapper for Android log calls, enables recording & displaying log
14+ * simple wrapper for Android log calls, enables recording and displaying log
1515 */
1616public class AppLog {
1717 // T for Tag
@@ -26,56 +26,105 @@ private AppLog() {
2626 throw new AssertionError ();
2727 }
2828
29- /*
30- * defaults to false, pass true to capture log so it can be displayed by AppLogViewerActivity
29+ /**
30+ * Capture log so it can be displayed by AppLogViewerActivity
31+ * @param enable A boolean flag to capture log. Default is false, pass true to enable recording
3132 */
3233 public static void enableRecording (boolean enable ) {
3334 mEnableRecording = enable ;
3435 }
3536
37+ /**
38+ * Sends a VERBOSE log message
39+ * @param tag Used to identify the source of a log message.
40+ * It usually identifies the class or activity where the log call occurs.
41+ * @param message The message you would like logged.
42+ */
3643 public static void v (T tag , String message ) {
3744 message = StringUtils .notNullStr (message );
3845 Log .v (TAG + "-" + tag .toString (), message );
3946 addEntry (tag , LogLevel .v , message );
4047 }
4148
49+ /**
50+ * Sends a DEBUG log message
51+ * @param tag Used to identify the source of a log message.
52+ * It usually identifies the class or activity where the log call occurs.
53+ * @param message The message you would like logged.
54+ */
4255 public static void d (T tag , String message ) {
4356 message = StringUtils .notNullStr (message );
4457 Log .d (TAG + "-" + tag .toString (), message );
4558 addEntry (tag , LogLevel .d , message );
4659 }
4760
61+ /**
62+ * Sends a INFO log message
63+ * @param tag Used to identify the source of a log message.
64+ * It usually identifies the class or activity where the log call occurs.
65+ * @param message The message you would like logged.
66+ */
4867 public static void i (T tag , String message ) {
4968 message = StringUtils .notNullStr (message );
5069 Log .i (TAG + "-" + tag .toString (), message );
5170 addEntry (tag , LogLevel .i , message );
5271 }
5372
73+ /**
74+ * Sends a WARN log message
75+ * @param tag Used to identify the source of a log message.
76+ * It usually identifies the class or activity where the log call occurs.
77+ * @param message The message you would like logged.
78+ */
5479 public static void w (T tag , String message ) {
5580 message = StringUtils .notNullStr (message );
5681 Log .w (TAG + "-" + tag .toString (), message );
5782 addEntry (tag , LogLevel .w , message );
5883 }
5984
85+ /**
86+ * Sends a ERROR log message
87+ * @param tag Used to identify the source of a log message.
88+ * It usually identifies the class or activity where the log call occurs.
89+ * @param message The message you would like logged.
90+ */
6091 public static void e (T tag , String message ) {
6192 message = StringUtils .notNullStr (message );
6293 Log .e (TAG + "-" + tag .toString (), message );
6394 addEntry (tag , LogLevel .e , message );
6495 }
6596
97+ /**
98+ * Send a ERROR log message and log the exception.
99+ * @param tag Used to identify the source of a log message.
100+ * It usually identifies the class or activity where the log call occurs.
101+ * @param message The message you would like logged.
102+ * @param tr An exception to log
103+ */
66104 public static void e (T tag , String message , Throwable tr ) {
67105 message = StringUtils .notNullStr (message );
68106 Log .e (TAG + "-" + tag .toString (), message , tr );
69107 addEntry (tag , LogLevel .e , message + " - exception: " + tr .getMessage ());
70108 addEntry (tag , LogLevel .e , "StackTrace: " + getStringStackTrace (tr ));
71109 }
72110
111+ /**
112+ * Sends a ERROR log message and the exception with StackTrace
113+ * @param tag Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
114+ * @param tr An exception to log to get StackTrace
115+ */
73116 public static void e (T tag , Throwable tr ) {
74117 Log .e (TAG + "-" + tag .toString (), tr .getMessage (), tr );
75118 addEntry (tag , LogLevel .e , tr .getMessage ());
76119 addEntry (tag , LogLevel .e , "StackTrace: " + getStringStackTrace (tr ));
77120 }
78121
122+ /**
123+ * Sends a ERROR log message
124+ * @param tag Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
125+ * @param volleyErrorMsg
126+ * @param statusCode
127+ */
79128 public static void e (T tag , String volleyErrorMsg , int statusCode ) {
80129 if (TextUtils .isEmpty (volleyErrorMsg )) {
81130 return ;
@@ -178,8 +227,10 @@ private static String getStringStackTrace(Throwable throwable) {
178227 return errors .toString ();
179228 }
180229
181- /*
182- * returns entire log as html for display (see AppLogViewerActivity)
230+ /**
231+ * Returns entire log as html for display (see AppLogViewerActivity)
232+ * @param context
233+ * @return Arraylist of Strings containing log messages
183234 */
184235 public static ArrayList <String > toHtmlList (Context context ) {
185236 ArrayList <String > items = new ArrayList <String >();
@@ -195,24 +246,26 @@ public static ArrayList<String> toHtmlList(Context context) {
195246 return items ;
196247 }
197248
198- /*
199- * returns entire log as plain text
249+ /**
250+ * Converts the entire log to plain text
251+ * @param context
252+ * @return The log as plain text
200253 */
201254 public static String toPlainText (Context context ) {
202255 StringBuilder sb = new StringBuilder ();
203256
204257 // add version & device info
205258 sb .append ("WordPress Android version: " + PackageUtils .getVersionName (context )).append ("\n " )
206- .append ("Android device name: " + DeviceUtils .getInstance ().getDeviceName (context )).append ("\n \n " );
259+ .append ("Android device name: " + DeviceUtils .getInstance ().getDeviceName (context )).append ("\n \n " );
207260
208261 Iterator <LogEntry > it = mLogEntries .iterator ();
209262 int lineNum = 1 ;
210263 while (it .hasNext ()) {
211- sb .append (String .format ("%02d - " , lineNum ))
212- .append (it .next ().mLogText )
213- .append ("\n " );
264+ sb .append (String .format ("%02d - " , lineNum ))
265+ .append (it .next ().mLogText )
266+ .append ("\n " );
214267 lineNum ++;
215268 }
216269 return sb .toString ();
217270 }
218- }
271+ }
0 commit comments