Merge lp:~mcveat/tomdroid/loggers-cleanup into lp:~tomdroid-maintainers/tomdroid/main

Proposed by Piotr Adamski
Status: Merged
Approved by: Olivier Bilodeau
Approved revision: 259
Merge reported by: Olivier Bilodeau
Merged at revision: not available
Proposed branch: lp:~mcveat/tomdroid/loggers-cleanup
Merge into: lp:~tomdroid-maintainers/tomdroid/main
Diff against target: 1070 lines (+248/-209)
16 files modified
src/org/tomdroid/Note.java (+9/-10)
src/org/tomdroid/NoteManager.java (+14/-13)
src/org/tomdroid/NoteProvider.java (+8/-15)
src/org/tomdroid/sync/SyncService.java (+12/-14)
src/org/tomdroid/sync/sd/SdCardSyncService.java (+18/-26)
src/org/tomdroid/sync/web/OAuthConnection.java (+8/-13)
src/org/tomdroid/sync/web/SnowySyncService.java (+15/-17)
src/org/tomdroid/sync/web/WebConnection.java (+9/-11)
src/org/tomdroid/ui/PreferencesActivity.java (+16/-17)
src/org/tomdroid/ui/Search.java (+8/-9)
src/org/tomdroid/ui/SyncMessageHandler.java (+6/-8)
src/org/tomdroid/ui/Tomdroid.java (+15/-22)
src/org/tomdroid/ui/ViewNote.java (+16/-17)
src/org/tomdroid/util/FirstNote.java (+3/-5)
src/org/tomdroid/util/NoteContentBuilder.java (+8/-12)
src/org/tomdroid/util/TLog.java (+83/-0)
To merge this branch: bzr merge lp:~mcveat/tomdroid/loggers-cleanup
Reviewer Review Type Date Requested Status
Olivier Bilodeau Approve
Review via email: mp+80501@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

Hello Piotr,

"if (Tomdroid.LOGGING_ENABLED)"s are written for all Log.xxx functions.

It is repetitious.
I think it will be more simpler if you create functions which check Tomdroid.LOGGING_ENABLED and use Log.xxx.

Regards,
Koichi Akabe

Revision history for this message
Alex Belisle Turcot (alex-belisleturcot) wrote :

Bu then, would the debug Strings be created every time, even when logging is
not enabled ?

check this:
http://stackoverflow.com/questions/963492/in-log4j-does-checking-isdebugenabled-before-logging-improve-performance

[quote]
*The guard statement (checking isDebugEnabled()) is there to prevent
potentially expensive computation of the log message*
...
*Better yet is to use a more up-to-date logging framework where the log
statements take a format string and a list of arguments to be substituted by
the formatter—but "lazily," only if the logger is enabled. This is the
approach taken by
slf4j<http://www.slf4j.org/apidocs/org/slf4j/Logger.html#debug%28java.lang.String,%20java.lang.Object%5B%5D%29>
.*
[/quote]

Current logging frameworks ensure sure that debug Strings are not
concatenated unless debug is enabled. I'm not sure how to do that in
Android, you may need to code this mini-framework yourself...

Regards,
Alex

On Thu, Oct 27, 2011 at 7:58 AM, Koichi Akabe <email address hidden> wrote:

> Hello Piotr,
>
> "if (Tomdroid.LOGGING_ENABLED)"s are written for all Log.xxx functions.
>
> It is repetitious.
> I think it will be more simpler if you create functions which check
> Tomdroid.LOGGING_ENABLED and use Log.xxx.
>
> Regards,
> Koichi Akabe
> --
> https://code.launchpad.net/~mcveat/tomdroid/loggers-cleanup/+merge/80501
> You are subscribed to branch lp:tomdroid.
>

Revision history for this message
Piotr Adamski (mcveat) wrote :

On Thu, Oct 27, 2011 at 2:25 PM, Alex Belisle Turcot
<email address hidden> wrote:
> Bu then, would the debug Strings be created every time, even when logging is
> not enabled ?

I was also concerned about that.

> Current logging frameworks ensure sure that debug Strings are not
> concatenated unless debug is enabled. I'm not sure how to do that in
> Android, you may need to code this mini-framework yourself...

Should be pretty straightforward, yet not so versatile with use of
java.text.MessageFormat and varargs. I'll try how it rolls this
evening.

Regards
Piotr

lp:~mcveat/tomdroid/loggers-cleanup updated
256. By Piotr Adamski

excluded turning off logging logic to separate clas TLog

257. By Piotr Adamski

merged with main

258. By Piotr Adamski

updated license note

259. By Piotr Adamski

removed forgotten debug statements

Revision history for this message
Piotr Adamski (mcveat) wrote :

I've implemented simple logging utility that should remove the boilerplate code of checking logging switch state, yet avoiding unnecessary string concatenations. Tell what you think about it.

Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

I think it is great work!!

Revision history for this message
Olivier Bilodeau (plaxx) wrote :

Good stuff! Thanks! Next time try not to re-organize imports please. Makes patches larger than they should be and merging more complicated.

review: Approve
Revision history for this message
Olivier Bilodeau (plaxx) wrote :

Turns out I needed to make additional changes. See https://code.launchpad.net/~tomdroid-dev/tomdroid/loggers-cleanup if you are interested.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/org/tomdroid/Note.java'
2--- src/org/tomdroid/Note.java 2011-09-05 19:47:25 +0000
3+++ src/org/tomdroid/Note.java 2011-10-27 17:18:24 +0000
4@@ -23,19 +23,18 @@
5 */
6 package org.tomdroid;
7
8-import java.util.regex.Matcher;
9-import java.util.regex.Pattern;
10-
11+import android.os.Handler;
12+import android.text.SpannableStringBuilder;
13+import android.text.format.Time;
14+import android.util.TimeFormatException;
15 import org.json.JSONArray;
16 import org.json.JSONObject;
17 import org.tomdroid.util.NoteContentBuilder;
18+import org.tomdroid.util.TLog;
19 import org.tomdroid.util.XmlUtils;
20
21-import android.os.Handler;
22-import android.text.SpannableStringBuilder;
23-import android.text.format.Time;
24-import android.util.Log;
25-import android.util.TimeFormatException;
26+import java.util.regex.Matcher;
27+import java.util.regex.Pattern;
28
29 public class Note {
30
31@@ -145,9 +144,9 @@
32 // Tomboy's (C# library) format: 2010-01-23T12:07:38.7743020-05:00
33 Matcher m = dateCleaner.matcher(lastChangeDateStr);
34 if (m.find()) {
35- Log.d(TAG, "I had to clean out extra sub-milliseconds from the date");
36+ TLog.d(TAG, "I had to clean out extra sub-milliseconds from the date");
37 lastChangeDateStr = m.group(1)+m.group(2);
38- Log.v(TAG, "new date: "+lastChangeDateStr);
39+ TLog.v(TAG, "new date: {0}", lastChangeDateStr);
40 }
41
42 lastChangeDate = new Time();
43
44=== modified file 'src/org/tomdroid/NoteManager.java'
45--- src/org/tomdroid/NoteManager.java 2011-09-05 19:47:25 +0000
46+++ src/org/tomdroid/NoteManager.java 2011-10-27 17:18:24 +0000
47@@ -24,20 +24,19 @@
48 */
49 package org.tomdroid;
50
51-import java.util.regex.Matcher;
52-import java.util.regex.Pattern;
53-
54-import org.tomdroid.ui.Tomdroid;
55-import org.tomdroid.util.NoteListCursorAdapter;
56-import org.tomdroid.util.XmlUtils;
57-
58 import android.app.Activity;
59 import android.content.ContentResolver;
60 import android.content.ContentValues;
61 import android.database.Cursor;
62 import android.net.Uri;
63-import android.util.Log;
64 import android.widget.ListAdapter;
65+import org.tomdroid.ui.Tomdroid;
66+import org.tomdroid.util.NoteListCursorAdapter;
67+import org.tomdroid.util.TLog;
68+import org.tomdroid.util.XmlUtils;
69+
70+import java.util.regex.Matcher;
71+import java.util.regex.Pattern;
72
73 public class NoteManager {
74
75@@ -107,17 +106,19 @@
76 if (managedCursor.getCount() == 0) {
77
78 // This note is not in the database yet we need to insert it
79- if (Tomdroid.LOGGING_ENABLED) Log.v(TAG,"A new note has been detected (not yet in db)");
80+ TLog.v(TAG, "A new note has been detected (not yet in db)");
81
82 Uri uri = cr.insert(Tomdroid.CONTENT_URI, values);
83
84- if (Tomdroid.LOGGING_ENABLED) Log.v(TAG,"Note inserted in content provider. ID: "+uri+" TITLE:"+note.getTitle()+" GUID:"+note.getGuid());
85+ TLog.v(TAG, "Note inserted in content provider. ID: {0} TITLE:{1} GUID:{2}", uri, note.getTitle(),
86+ note.getGuid());
87 } else {
88
89 // Overwrite the previous note if it exists
90 cr.update(Tomdroid.CONTENT_URI, values, Note.GUID+" = ?", whereArgs);
91
92- if (Tomdroid.LOGGING_ENABLED) Log.v(TAG,"Note updated in content provider. TITLE:"+note.getTitle()+" GUID:"+note.getGuid());
93+ TLog.v(TAG, "Note updated in content provider. TITLE:{0} GUID:{1}", note.getTitle(),
94+ note.getGuid());
95 }
96 }
97
98@@ -209,7 +210,7 @@
99 }
100 else {
101 // TODO send an error to the user
102- if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "Cursor returned null or 0 notes");
103+ TLog.d(TAG, "Cursor returned null or 0 notes");
104 }
105
106 return id;
107@@ -229,7 +230,7 @@
108 Matcher m = stripTitle.matcher(xmlContent);
109 if (m.find()) {
110 xmlContent = xmlContent.substring(m.end(), xmlContent.length());
111- if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "stripped the title from note-content");
112+ TLog.d(TAG, "stripped the title from note-content");
113 }
114
115 return xmlContent;
116
117=== modified file 'src/org/tomdroid/NoteProvider.java'
118--- src/org/tomdroid/NoteProvider.java 2010-09-17 20:37:42 +0000
119+++ src/org/tomdroid/NoteProvider.java 2011-10-27 17:18:24 +0000
120@@ -43,16 +43,7 @@
121 */
122 package org.tomdroid;
123
124-import java.util.HashMap;
125-import java.util.UUID;
126-
127-import org.tomdroid.ui.Tomdroid;
128-
129-import android.content.ContentProvider;
130-import android.content.ContentUris;
131-import android.content.ContentValues;
132-import android.content.Context;
133-import android.content.UriMatcher;
134+import android.content.*;
135 import android.content.res.Resources;
136 import android.database.Cursor;
137 import android.database.SQLException;
138@@ -61,7 +52,11 @@
139 import android.database.sqlite.SQLiteQueryBuilder;
140 import android.net.Uri;
141 import android.text.TextUtils;
142-import android.util.Log;
143+import org.tomdroid.ui.Tomdroid;
144+import org.tomdroid.util.TLog;
145+
146+import java.util.HashMap;
147+import java.util.UUID;
148
149 public class NoteProvider extends ContentProvider {
150
151@@ -107,10 +102,8 @@
152
153 @Override
154 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
155- if (Tomdroid.LOGGING_ENABLED) {
156- Log.d(TAG, "Upgrading database from version " + oldVersion + " to "
157- + newVersion + ", which will destroy all old data");
158- }
159+ TLog.d(TAG, "Upgrading database from version {0} to {1}, which will destroy all old data",
160+ oldVersion, newVersion);
161 db.execSQL("DROP TABLE IF EXISTS notes");
162 onCreate(db);
163 }
164
165=== modified file 'src/org/tomdroid/sync/SyncService.java'
166--- src/org/tomdroid/sync/SyncService.java 2010-12-13 02:55:59 +0000
167+++ src/org/tomdroid/sync/SyncService.java 2011-10-27 17:18:24 +0000
168@@ -24,23 +24,21 @@
169 */
170 package org.tomdroid.sync;
171
172-import java.util.ArrayList;
173-import java.util.HashMap;
174-import java.util.concurrent.ExecutorService;
175-import java.util.concurrent.Executors;
176-
177-import org.tomdroid.Note;
178-import org.tomdroid.NoteManager;
179-import org.tomdroid.ui.Tomdroid;
180-import org.tomdroid.util.ErrorList;
181-
182-import org.tomdroid.R;
183 import android.app.Activity;
184 import android.database.Cursor;
185 import android.os.Handler;
186 import android.os.Message;
187-import android.util.Log;
188 import android.widget.Toast;
189+import org.tomdroid.Note;
190+import org.tomdroid.NoteManager;
191+import org.tomdroid.R;
192+import org.tomdroid.util.ErrorList;
193+import org.tomdroid.util.TLog;
194+
195+import java.util.ArrayList;
196+import java.util.HashMap;
197+import java.util.concurrent.ExecutorService;
198+import java.util.concurrent.Executors;
199
200 public abstract class SyncService {
201
202@@ -174,7 +172,7 @@
203 } else {
204
205 // TODO send an error to the user
206- if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "Cursor returned null or 0 notes");
207+ TLog.d(TAG, "Cursor returned null or 0 notes");
208 }
209 }
210
211@@ -214,7 +212,7 @@
212
213 protected void setSyncProgress(int progress) {
214 synchronized (TAG) {
215- Log.v(TAG, "sync progress: " + progress);
216+ TLog.v(TAG, "sync progress: {0}", progress);
217 Message progressMessage = new Message();
218 progressMessage.what = SYNC_PROGRESS;
219 progressMessage.arg1 = progress;
220
221=== modified file 'src/org/tomdroid/sync/sd/SdCardSyncService.java'
222--- src/org/tomdroid/sync/sd/SdCardSyncService.java 2011-09-05 19:47:25 +0000
223+++ src/org/tomdroid/sync/sd/SdCardSyncService.java 2011-10-27 17:18:24 +0000
224@@ -24,30 +24,22 @@
225 */
226 package org.tomdroid.sync.sd;
227
228-import java.io.File;
229-import java.io.FileInputStream;
230-import java.io.FilenameFilter;
231-import java.io.IOException;
232-import java.io.InputStreamReader;
233-import java.io.Reader;
234-import java.io.StringReader;
235-import java.util.regex.Matcher;
236-import java.util.regex.Pattern;
237-
238-import javax.xml.parsers.SAXParser;
239-import javax.xml.parsers.SAXParserFactory;
240-
241+import android.app.Activity;
242+import android.os.Handler;
243+import android.util.TimeFormatException;
244 import org.tomdroid.Note;
245 import org.tomdroid.sync.SyncService;
246 import org.tomdroid.ui.Tomdroid;
247 import org.tomdroid.util.ErrorList;
248+import org.tomdroid.util.TLog;
249 import org.xml.sax.InputSource;
250 import org.xml.sax.XMLReader;
251
252-import android.app.Activity;
253-import android.os.Handler;
254-import android.util.Log;
255-import android.util.TimeFormatException;
256+import javax.xml.parsers.SAXParser;
257+import javax.xml.parsers.SAXParserFactory;
258+import java.io.*;
259+import java.util.regex.Matcher;
260+import java.util.regex.Pattern;
261
262 public class SdCardSyncService extends SyncService {
263
264@@ -89,18 +81,18 @@
265 setSyncProgress(0);
266
267 // start loading local notes
268- if (Tomdroid.LOGGING_ENABLED) Log.v(TAG, "Loading local notes");
269+ TLog.v(TAG, "Loading local notes");
270
271 File path = new File(Tomdroid.NOTES_PATH);
272
273 if (!path.exists())
274 path.mkdir();
275
276- Log.i(TAG, "Path "+path+" exists: "+path.exists());
277+ TLog.i(TAG, "Path {0} exists: {1}", path, path.exists());
278
279 // Check a second time, if not the most likely cause is the volume doesn't exist
280 if(!path.exists()) {
281- if (Tomdroid.LOGGING_ENABLED) Log.w(TAG, "Couldn't create "+path);
282+ TLog.w(TAG, "Couldn't create {0}", path);
283 sendMessage(NO_SD_CARD);
284 setSyncProgress(100);
285 return;
286@@ -111,7 +103,7 @@
287
288 // If there are no notes, warn the UI through an empty message
289 if (fileList == null || fileList.length == 0) {
290- if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "There are no notes in "+path);
291+ TLog.i(TAG, "There are no notes in {0}", path);
292 sendMessage(PARSING_NO_NOTES);
293 setSyncProgress(100);
294 return;
295@@ -169,7 +161,7 @@
296 contents = readFile();
297 } catch (IOException e) {
298 e.printStackTrace();
299- if (Tomdroid.LOGGING_ENABLED) Log.w(TAG, "Something went wrong trying to read the note");
300+ TLog.w(TAG, "Something went wrong trying to read the note");
301 sendMessage(PARSING_FAILED, ErrorList.createError(note, e));
302 onWorkDone();
303 return;
304@@ -193,27 +185,27 @@
305 StringReader sr = new StringReader(contents);
306 InputSource is = new InputSource(sr);
307
308- if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "parsing note");
309+ TLog.d(TAG, "parsing note");
310 xr.parse(is);
311
312 // TODO wrap and throw a new exception here
313 } catch (Exception e) {
314 e.printStackTrace();
315- if(e instanceof TimeFormatException) Log.e(TAG, "Problem parsing the note's date and time");
316+ if(e instanceof TimeFormatException) TLog.e(TAG, "Problem parsing the note's date and time");
317 sendMessage(PARSING_FAILED, ErrorList.createErrorWithContents(note, e, contents));
318 onWorkDone();
319 return;
320 }
321
322 // extract the <note-content..>...</note-content>
323- if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "retrieving what is inside of note-content");
324+ TLog.d(TAG, "retrieving what is inside of note-content");
325
326 // FIXME here we are re-reading the whole note just to grab note-content out, there is probably a best way to do this (I'm talking to you xmlpull.org!)
327 Matcher m = note_content.matcher(contents);
328 if (m.find()) {
329 note.setXmlContent(m.group(1));
330 } else {
331- if (Tomdroid.LOGGING_ENABLED) Log.w(TAG, "Something went wrong trying to grab the note-content out of a note");
332+ TLog.w(TAG, "Something went wrong trying to grab the note-content out of a note");
333 sendMessage(PARSING_FAILED, ErrorList.createErrorWithContents(note, "Something went wrong trying to grab the note-content out of a note", contents));
334 onWorkDone();
335 return;
336
337=== modified file 'src/org/tomdroid/sync/web/OAuthConnection.java'
338--- src/org/tomdroid/sync/web/OAuthConnection.java 2010-08-31 21:00:35 +0000
339+++ src/org/tomdroid/sync/web/OAuthConnection.java 2011-10-27 17:18:24 +0000
340@@ -22,9 +22,7 @@
341 */
342 package org.tomdroid.sync.web;
343
344-import java.io.UnsupportedEncodingException;
345-import java.net.UnknownHostException;
346-
347+import android.net.Uri;
348 import oauth.signpost.OAuthConsumer;
349 import oauth.signpost.OAuthProvider;
350 import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
351@@ -33,7 +31,6 @@
352 import oauth.signpost.exception.OAuthExpectationFailedException;
353 import oauth.signpost.exception.OAuthMessageSignerException;
354 import oauth.signpost.exception.OAuthNotAuthorizedException;
355-
356 import org.apache.http.HttpRequest;
357 import org.apache.http.HttpResponse;
358 import org.apache.http.client.methods.HttpGet;
359@@ -41,11 +38,11 @@
360 import org.apache.http.entity.StringEntity;
361 import org.json.JSONException;
362 import org.json.JSONObject;
363-import org.tomdroid.ui.Tomdroid;
364 import org.tomdroid.util.Preferences;
365+import org.tomdroid.util.TLog;
366
367-import android.net.Uri;
368-import android.util.Log;
369+import java.io.UnsupportedEncodingException;
370+import java.net.UnknownHostException;
371
372 public class OAuthConnection extends WebConnection {
373
374@@ -168,14 +165,14 @@
375 return null;
376 }
377
378- if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "Authorization URL : "+url);
379+ TLog.i(TAG, "Authorization URL : {0}", url);
380
381 return Uri.parse(url);
382 }
383
384 public boolean getAccess(String verifier) throws UnknownHostException {
385
386- Log.i(TAG, "Verifier: "+verifier);
387+ TLog.i(TAG, "Verifier: {0}", verifier);
388
389 // this method shouldn't have been called
390 if (isAuthenticated())
391@@ -183,9 +180,7 @@
392
393 if (!requestToken.equals("") && !requestTokenSecret.equals("")) {
394 consumer.setTokenWithSecret(requestToken, requestTokenSecret);
395- if(Tomdroid.LOGGING_ENABLED) {
396- Log.d(TAG, "Added request token "+requestTokenSecret+" and request token secret "+requestTokenSecret);
397- }
398+ TLog.d(TAG, "Added request token {0} and request token secret {1)", requestTokenSecret, requestTokenSecret);
399 }
400 else
401 return false;
402@@ -225,7 +220,7 @@
403
404 saveConfiguration();
405
406- if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "Got access token "+consumer.getToken()+".");
407+ TLog.i(TAG, "Got access token {0}.", consumer.getToken());
408
409 return true;
410 }
411
412=== modified file 'src/org/tomdroid/sync/web/SnowySyncService.java'
413--- src/org/tomdroid/sync/web/SnowySyncService.java 2010-11-05 23:54:32 +0000
414+++ src/org/tomdroid/sync/web/SnowySyncService.java 2011-10-27 17:18:24 +0000
415@@ -22,24 +22,22 @@
416 */
417 package org.tomdroid.sync.web;
418
419-import java.net.UnknownHostException;
420-import java.util.ArrayList;
421-
422+import android.app.Activity;
423+import android.net.Uri;
424+import android.os.Handler;
425+import android.os.Message;
426 import org.json.JSONArray;
427 import org.json.JSONException;
428 import org.json.JSONObject;
429 import org.tomdroid.Note;
430 import org.tomdroid.sync.ServiceAuth;
431 import org.tomdroid.sync.SyncService;
432-import org.tomdroid.ui.Tomdroid;
433 import org.tomdroid.util.ErrorList;
434 import org.tomdroid.util.Preferences;
435+import org.tomdroid.util.TLog;
436
437-import android.app.Activity;
438-import android.net.Uri;
439-import android.os.Handler;
440-import android.os.Message;
441-import android.util.Log;
442+import java.net.UnknownHostException;
443+import java.util.ArrayList;
444
445 public class SnowySyncService extends SyncService implements ServiceAuth {
446
447@@ -88,7 +86,7 @@
448 authUri = auth.getAuthorizationUrl(server);
449
450 } catch (UnknownHostException e) {
451- Log.e(TAG, "Internet connection not available");
452+ TLog.e(TAG, "Internet connection not available");
453 sendMessage(NO_INTERNET);
454 }
455
456@@ -114,12 +112,12 @@
457 boolean result = auth.getAccess(uri.getQueryParameter("oauth_verifier"));
458
459 if (result) {
460- if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "The authorization process is complete.");
461+ TLog.i(TAG, "The authorization process is complete.");
462 } else {
463- Log.e(TAG, "Something went wrong during the authorization process.");
464+ TLog.e(TAG, "Something went wrong during the authorization process.");
465 }
466 } catch (UnknownHostException e) {
467- Log.e(TAG, "Internet connection not available");
468+ TLog.e(TAG, "Internet connection not available");
469 sendMessage(NO_INTERNET);
470 }
471
472@@ -140,7 +138,7 @@
473
474 // start loading snowy notes
475 setSyncProgress(0);
476- if (Tomdroid.LOGGING_ENABLED) Log.v(TAG, "Loading Snowy notes");
477+ TLog.v(TAG, "Loading Snowy notes");
478
479 final String userRef = Preferences.getString(Preferences.Key.SYNC_SERVER_USER_API);
480
481@@ -193,7 +191,7 @@
482 jsonNote = notes.getJSONObject(i);
483 insertNote(new Note(jsonNote));
484 } catch (JSONException e) {
485- Log.e(TAG, "Problem parsing the server response", e);
486+ TLog.e(TAG, e, "Problem parsing the server response");
487 String json = (jsonNote != null) ? jsonNote.toString(2) : rawResponse;
488 sendMessage(PARSING_FAILED, ErrorList.createErrorWithContents("JSON parsing", "json", e, json));
489 }
490@@ -207,7 +205,7 @@
491 .getLong("latest-sync-revision"));
492
493 } catch (JSONException e) {
494- Log.e(TAG, "Problem parsing the server response", e);
495+ TLog.e(TAG, e, "Problem parsing the server response");
496 sendMessage(PARSING_FAILED, ErrorList.createErrorWithContents("JSON parsing", "json", e, rawResponse));
497 setSyncProgress(100);
498 return;
499@@ -216,7 +214,7 @@
500 setSyncProgress(100);
501
502 } catch (java.net.UnknownHostException e) {
503- Log.e(TAG, "Internet connection not available");
504+ TLog.e(TAG, "Internet connection not available");
505 sendMessage(NO_INTERNET);
506 setSyncProgress(100);
507 return;
508
509=== modified file 'src/org/tomdroid/sync/web/WebConnection.java'
510--- src/org/tomdroid/sync/web/WebConnection.java 2010-08-30 16:33:02 +0000
511+++ src/org/tomdroid/sync/web/WebConnection.java 2011-10-27 17:18:24 +0000
512@@ -22,21 +22,19 @@
513 */
514 package org.tomdroid.sync.web;
515
516+import org.apache.http.HttpEntity;
517+import org.apache.http.HttpResponse;
518+import org.apache.http.client.ClientProtocolException;
519+import org.apache.http.client.methods.HttpUriRequest;
520+import org.apache.http.impl.client.DefaultHttpClient;
521+import org.tomdroid.util.TLog;
522+
523 import java.io.BufferedReader;
524 import java.io.IOException;
525 import java.io.InputStream;
526 import java.io.InputStreamReader;
527 import java.net.UnknownHostException;
528
529-import org.apache.http.HttpEntity;
530-import org.apache.http.HttpResponse;
531-import org.apache.http.client.ClientProtocolException;
532-import org.apache.http.client.methods.HttpUriRequest;
533-import org.apache.http.impl.client.DefaultHttpClient;
534-import org.tomdroid.ui.Tomdroid;
535-
536-import android.util.Log;
537-
538 public abstract class WebConnection {
539
540 private static final String TAG = "WebConnection";
541@@ -80,7 +78,7 @@
542 String result = null;
543
544 // Examine the response status
545- if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "Response status : "+response.getStatusLine().toString());
546+ TLog.i(TAG, "Response status : {0}", response.getStatusLine().toString());
547
548 // Get hold of the response entity
549 HttpEntity entity = response.getEntity();
550@@ -96,7 +94,7 @@
551
552 result = convertStreamToString(instream);
553
554- if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "Received : "+result);
555+ TLog.i(TAG, "Received : {0}", result);
556
557 // Closing the input stream will trigger connection release
558 instream.close();
559
560=== modified file 'src/org/tomdroid/ui/PreferencesActivity.java'
561--- src/org/tomdroid/ui/PreferencesActivity.java 2011-09-04 17:48:08 +0000
562+++ src/org/tomdroid/ui/PreferencesActivity.java 2011-10-27 17:18:24 +0000
563@@ -23,22 +23,11 @@
564 */
565 package org.tomdroid.ui;
566
567-import java.util.ArrayList;
568-
569-import org.tomdroid.NoteManager;
570-import org.tomdroid.R;
571-import org.tomdroid.sync.ServiceAuth;
572-import org.tomdroid.sync.SyncManager;
573-import org.tomdroid.sync.SyncService;
574-import org.tomdroid.util.FirstNote;
575-import org.tomdroid.util.Preferences;
576-import org.tomdroid.util.SearchSuggestionProvider;
577-
578 import android.app.AlertDialog;
579 import android.app.ProgressDialog;
580 import android.content.DialogInterface;
581+import android.content.DialogInterface.OnClickListener;
582 import android.content.Intent;
583-import android.content.DialogInterface.OnClickListener;
584 import android.net.Uri;
585 import android.os.Bundle;
586 import android.os.Handler;
587@@ -46,12 +35,22 @@
588 import android.preference.EditTextPreference;
589 import android.preference.ListPreference;
590 import android.preference.Preference;
591-import android.preference.PreferenceActivity;
592 import android.preference.Preference.OnPreferenceChangeListener;
593 import android.preference.Preference.OnPreferenceClickListener;
594+import android.preference.PreferenceActivity;
595 import android.provider.SearchRecentSuggestions;
596-import android.util.Log;
597 import android.widget.Toast;
598+import org.tomdroid.NoteManager;
599+import org.tomdroid.R;
600+import org.tomdroid.sync.ServiceAuth;
601+import org.tomdroid.sync.SyncManager;
602+import org.tomdroid.sync.SyncService;
603+import org.tomdroid.util.FirstNote;
604+import org.tomdroid.util.Preferences;
605+import org.tomdroid.util.SearchSuggestionProvider;
606+import org.tomdroid.util.TLog;
607+
608+import java.util.ArrayList;
609
610 public class PreferencesActivity extends PreferenceActivity {
611
612@@ -89,7 +88,7 @@
613
614 // did the selection change?
615 if (!syncService.getValue().contentEquals(selectedSyncServiceKey)) {
616- Log.d(TAG, "preference change triggered");
617+ TLog.d(TAG, "preference change triggered");
618
619 syncServiceChanged(selectedSyncServiceKey);
620 }
621@@ -126,7 +125,7 @@
622 Toast.makeText(getBaseContext(),
623 getString(R.string.deletedSearchHistory),
624 Toast.LENGTH_LONG).show();
625- Log.d(TAG, "Deleted search history.");
626+ TLog.d(TAG, "Deleted search history.");
627
628 return true;
629 }
630@@ -145,7 +144,7 @@
631 }
632
633 // service needs authentication
634- Log.i(TAG, "Creating dialog");
635+ TLog.i(TAG, "Creating dialog");
636
637 final ProgressDialog authProgress = ProgressDialog.show(this, "",
638 getString(R.string.prefSyncCompleteAuth), true, false);
639
640=== modified file 'src/org/tomdroid/ui/Search.java'
641--- src/org/tomdroid/ui/Search.java 2011-09-04 17:48:08 +0000
642+++ src/org/tomdroid/ui/Search.java 2011-10-27 17:18:24 +0000
643@@ -23,12 +23,6 @@
644 */
645 package org.tomdroid.ui;
646
647-import org.tomdroid.Note;
648-import org.tomdroid.NoteManager;
649-import org.tomdroid.R;
650-import org.tomdroid.sync.SyncManager;
651-import org.tomdroid.util.SearchSuggestionProvider;
652-
653 import android.app.ListActivity;
654 import android.app.SearchManager;
655 import android.content.Intent;
656@@ -38,11 +32,16 @@
657 import android.os.Bundle;
658 import android.os.Handler;
659 import android.provider.SearchRecentSuggestions;
660-import android.util.Log;
661 import android.view.View;
662 import android.widget.ListAdapter;
663 import android.widget.ListView;
664 import android.widget.TextView;
665+import org.tomdroid.Note;
666+import org.tomdroid.NoteManager;
667+import org.tomdroid.R;
668+import org.tomdroid.sync.SyncManager;
669+import org.tomdroid.util.SearchSuggestionProvider;
670+import org.tomdroid.util.TLog;
671
672 public class Search extends ListActivity {
673
674@@ -94,7 +93,7 @@
675 }
676
677 public void showResults(String query) {
678- if (Tomdroid.LOGGING_ENABLED) Log.d(TAG,"Start searching for: "+query);
679+ TLog.d(TAG, "Start searching for: {0}", query);
680
681
682 // adapter that binds the ListView UI to the notes in the note manager
683@@ -103,7 +102,7 @@
684
685 // set the view shown when query not found
686 listEmptyView = (TextView) findViewById(R.id.no_results);
687- listEmptyView.setText(getString(R.string.strNoResults, new Object[] {query}));
688+ listEmptyView.setText(getString(R.string.strNoResults, query));
689 getListView().setEmptyView(listEmptyView);
690 }
691
692
693=== modified file 'src/org/tomdroid/ui/SyncMessageHandler.java'
694--- src/org/tomdroid/ui/SyncMessageHandler.java 2010-12-13 02:55:59 +0000
695+++ src/org/tomdroid/ui/SyncMessageHandler.java 2011-10-27 17:18:24 +0000
696@@ -24,24 +24,23 @@
697 */
698 package org.tomdroid.ui;
699
700-import org.tomdroid.R;
701-import org.tomdroid.sync.SyncManager;
702-import org.tomdroid.sync.SyncService;
703-import org.tomdroid.util.ErrorList;
704-
705 import android.app.Activity;
706 import android.app.AlertDialog;
707 import android.content.DialogInterface;
708 import android.content.DialogInterface.OnClickListener;
709 import android.os.Handler;
710 import android.os.Message;
711-import android.util.Log;
712 import android.view.View;
713 import android.view.animation.Animation;
714 import android.view.animation.AnimationUtils;
715 import android.view.animation.RotateAnimation;
716 import android.widget.ImageView;
717 import android.widget.Toast;
718+import org.tomdroid.R;
719+import org.tomdroid.sync.SyncManager;
720+import org.tomdroid.sync.SyncService;
721+import org.tomdroid.util.ErrorList;
722+import org.tomdroid.util.TLog;
723
724 public class SyncMessageHandler extends Handler {
725
726@@ -109,8 +108,7 @@
727 break;
728
729 default:
730- if (Tomdroid.LOGGING_ENABLED)
731- Log.i(TAG, "handler called with an unknown message");
732+ TLog.i(TAG, "handler called with an unknown message");
733 break;
734
735 }
736
737=== modified file 'src/org/tomdroid/ui/Tomdroid.java'
738--- src/org/tomdroid/ui/Tomdroid.java 2011-09-04 17:48:08 +0000
739+++ src/org/tomdroid/ui/Tomdroid.java 2011-10-27 17:18:24 +0000
740@@ -24,23 +24,13 @@
741 */
742 package org.tomdroid.ui;
743
744-import org.tomdroid.Note;
745-import org.tomdroid.NoteManager;
746-import org.tomdroid.R;
747-import org.tomdroid.sync.ServiceAuth;
748-import org.tomdroid.sync.SyncManager;
749-import org.tomdroid.sync.SyncService;
750-import org.tomdroid.util.FirstNote;
751-import org.tomdroid.util.Preferences;
752-import org.tomdroid.util.Send;
753-
754 import android.app.AlertDialog;
755 import android.app.ListActivity;
756 import android.app.ProgressDialog;
757 import android.content.Context;
758 import android.content.DialogInterface;
759+import android.content.DialogInterface.OnClickListener;
760 import android.content.Intent;
761-import android.content.DialogInterface.OnClickListener;
762 import android.content.pm.PackageManager.NameNotFoundException;
763 import android.database.Cursor;
764 import android.net.Uri;
765@@ -48,17 +38,22 @@
766 import android.os.Environment;
767 import android.os.Handler;
768 import android.os.Message;
769-import android.util.Log;
770-import android.view.ContextMenu;
771-import android.view.Menu;
772-import android.view.MenuInflater;
773-import android.view.MenuItem;
774-import android.view.View;
775+import android.view.*;
776 import android.view.ContextMenu.ContextMenuInfo;
777+import android.widget.AdapterView.AdapterContextMenuInfo;
778 import android.widget.ListAdapter;
779 import android.widget.ListView;
780 import android.widget.TextView;
781-import android.widget.AdapterView.AdapterContextMenuInfo;
782+import org.tomdroid.Note;
783+import org.tomdroid.NoteManager;
784+import org.tomdroid.R;
785+import org.tomdroid.sync.ServiceAuth;
786+import org.tomdroid.sync.SyncManager;
787+import org.tomdroid.sync.SyncService;
788+import org.tomdroid.util.FirstNote;
789+import org.tomdroid.util.Preferences;
790+import org.tomdroid.util.Send;
791+import org.tomdroid.util.TLog;
792
793 public class Tomdroid extends ListActivity {
794
795@@ -75,8 +70,6 @@
796 // TODO hardcoded for now
797 public static final String NOTES_PATH = Environment.getExternalStorageDirectory()
798 + "/tomdroid/";
799- // Logging should be disabled for release builds
800- public static final boolean LOGGING_ENABLED = false;
801 // Set this to false for release builds, the reason should be obvious
802 public static final boolean CLEAR_PREFERENCES = false;
803
804@@ -100,7 +93,7 @@
805
806 // did we already show the warning and got destroyed by android's activity killer?
807 if (Preferences.getBoolean(Preferences.Key.FIRST_RUN)) {
808- Log.i(TAG, "Tomdroid is first run.");
809+ TLog.i(TAG, "Tomdroid is first run.");
810
811 // add a first explanatory note
812 NoteManager.putNote(this, FirstNote.createFirstNote());
813@@ -197,7 +190,7 @@
814 Uri uri = intent.getData();
815
816 if (uri != null && uri.getScheme().equals("tomdroid")) {
817- Log.i(TAG, "Got url : " + uri.toString());
818+ TLog.i(TAG, "Got url : {0}", uri.toString());
819
820 final ProgressDialog dialog = ProgressDialog.show(this, "", getString(R.string.prefSyncCompleteAuth), true, false);
821
822
823=== modified file 'src/org/tomdroid/ui/ViewNote.java'
824--- src/org/tomdroid/ui/ViewNote.java 2011-09-05 15:05:46 +0000
825+++ src/org/tomdroid/ui/ViewNote.java 2011-10-27 17:18:24 +0000
826@@ -23,22 +23,11 @@
827 */
828 package org.tomdroid.ui;
829
830-import java.util.regex.Matcher;
831-import java.util.regex.Pattern;
832-
833-import org.tomdroid.Note;
834-import org.tomdroid.NoteManager;
835-import org.tomdroid.R;
836-import org.tomdroid.sync.SyncManager;
837-import org.tomdroid.util.LinkifyPhone;
838-import org.tomdroid.util.NoteContentBuilder;
839-import org.tomdroid.util.Send;
840-
841 import android.app.Activity;
842 import android.app.AlertDialog;
843 import android.content.DialogInterface;
844+import android.content.DialogInterface.OnClickListener;
845 import android.content.Intent;
846-import android.content.DialogInterface.OnClickListener;
847 import android.database.Cursor;
848 import android.graphics.Color;
849 import android.net.Uri;
850@@ -48,11 +37,21 @@
851 import android.text.SpannableStringBuilder;
852 import android.text.util.Linkify;
853 import android.text.util.Linkify.TransformFilter;
854-import android.util.Log;
855 import android.view.Menu;
856 import android.view.MenuInflater;
857 import android.view.MenuItem;
858 import android.widget.TextView;
859+import org.tomdroid.Note;
860+import org.tomdroid.NoteManager;
861+import org.tomdroid.R;
862+import org.tomdroid.sync.SyncManager;
863+import org.tomdroid.util.LinkifyPhone;
864+import org.tomdroid.util.NoteContentBuilder;
865+import org.tomdroid.util.Send;
866+import org.tomdroid.util.TLog;
867+
868+import java.util.regex.Matcher;
869+import java.util.regex.Pattern;
870
871 // TODO this class is starting to smell
872 public class ViewNote extends Activity {
873@@ -91,7 +90,7 @@
874 if (uri != null) {
875
876 // We were triggered by an Intent URI
877- if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "ViewNote started: Intent-filter triggered.");
878+ TLog.d(TAG, "ViewNote started: Intent-filter triggered.");
879
880 // TODO validate the good action?
881 // intent.getAction()
882@@ -107,7 +106,7 @@
883
884 } else {
885
886- if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "The note "+uri+" doesn't exist");
887+ TLog.d(TAG, "The note {0} doesn't exist", uri);
888
889 // TODO put error string in a translatable resource
890 new AlertDialog.Builder(this)
891@@ -123,7 +122,7 @@
892 }
893 } else {
894
895- if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "The Intent's data was null.");
896+ TLog.d(TAG, "The Intent's data was null.");
897
898 // TODO put error string in a translatable resource
899 new AlertDialog.Builder(this)
900@@ -250,7 +249,7 @@
901 } else {
902
903 // TODO send an error to the user
904- if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "Cursor returned null or 0 notes");
905+ TLog.d(TAG, "Cursor returned null or 0 notes");
906 }
907
908 return null;
909
910=== modified file 'src/org/tomdroid/util/FirstNote.java'
911--- src/org/tomdroid/util/FirstNote.java 2010-10-09 19:58:11 +0000
912+++ src/org/tomdroid/util/FirstNote.java 2011-10-27 17:18:24 +0000
913@@ -22,13 +22,11 @@
914 */
915 package org.tomdroid.util;
916
917+import org.tomdroid.Note;
918+
919 import java.util.MissingResourceException;
920 import java.util.ResourceBundle;
921
922-import org.tomdroid.Note;
923-
924-import android.util.Log;
925-
926 /**
927 * Creates an introductory note object
928 * @author Olivier Bilodeau <olivier@bottomlesspit.org>
929@@ -40,7 +38,7 @@
930 private static final String TAG = "FirstNote";
931
932 public static Note createFirstNote() {
933- Log.v(TAG, "Creating first note");
934+ TLog.v(TAG, "Creating first note");
935
936 Note note = new Note();
937
938
939=== modified file 'src/org/tomdroid/util/NoteContentBuilder.java'
940--- src/org/tomdroid/util/NoteContentBuilder.java 2011-09-05 19:45:38 +0000
941+++ src/org/tomdroid/util/NoteContentBuilder.java 2011-10-27 17:18:24 +0000
942@@ -22,19 +22,15 @@
943 */
944 package org.tomdroid.util;
945
946-import java.io.StringReader;
947-
948-import javax.xml.parsers.SAXParser;
949-import javax.xml.parsers.SAXParserFactory;
950-
951-import org.tomdroid.ui.Tomdroid;
952-import org.tomdroid.xml.NoteContentHandler;
953-import org.xml.sax.InputSource;
954-
955 import android.os.Handler;
956 import android.os.Message;
957 import android.text.SpannableStringBuilder;
958-import android.util.Log;
959+import org.tomdroid.xml.NoteContentHandler;
960+import org.xml.sax.InputSource;
961+
962+import javax.xml.parsers.SAXParser;
963+import javax.xml.parsers.SAXParserFactory;
964+import java.io.StringReader;
965
966 public class NoteContentBuilder implements Runnable {
967
968@@ -89,12 +85,12 @@
969 spf.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
970 SAXParser sp = spf.newSAXParser();
971
972- if (Tomdroid.LOGGING_ENABLED) Log.v(TAG, "parsing note");
973+ TLog.v(TAG, "parsing note");
974 sp.parse(noteContentIs, new NoteContentHandler(noteContent));
975 } catch (Exception e) {
976 e.printStackTrace();
977 // TODO handle error in a more granular way
978- Log.e(TAG, "There was an error parsing the note.");
979+ TLog.e(TAG, "There was an error parsing the note.");
980 successful = false;
981 }
982
983
984=== added file 'src/org/tomdroid/util/TLog.java'
985--- src/org/tomdroid/util/TLog.java 1970-01-01 00:00:00 +0000
986+++ src/org/tomdroid/util/TLog.java 2011-10-27 17:18:24 +0000
987@@ -0,0 +1,83 @@
988+/*
989+ * Tomdroid
990+ * Tomboy on Android
991+ * http://www.launchpad.net/tomdroid
992+ *
993+ * Copyright 2011 Piotr Adamski <mcveat@gmail.com>
994+ *
995+ * This file is part of Tomdroid.
996+ *
997+ * Tomdroid is free software: you can redistribute it and/or modify
998+ * it under the terms of the GNU General Public License as published by
999+ * the Free Software Foundation, either version 3 of the License, or
1000+ * (at your option) any later version.
1001+ *
1002+ * Tomdroid is distributed in the hope that it will be useful,
1003+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1004+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1005+ * GNU General Public License for more details.
1006+ *
1007+ * You should have received a copy of the GNU General Public License
1008+ * along with Tomdroid. If not, see <http://www.gnu.org/licenses/>.
1009+ */
1010+package org.tomdroid.util;
1011+
1012+import android.util.Log;
1013+
1014+import static java.text.MessageFormat.format;
1015+
1016+/**
1017+ * @author Piotr Adamski <mcveat@gmail.com>
1018+ */
1019+public class TLog {
1020+ // Logging should be disabled for release builds
1021+ private static final boolean LOGGING_ENABLED = false;
1022+
1023+ public static void v(String tag, Throwable t, String msg, Object... args) {
1024+ if (LOGGING_ENABLED) Log.v(tag, format(msg, args), t);
1025+ }
1026+
1027+ public static void v(String tag, String msg, Object... args) {
1028+ v(tag, null, msg, args);
1029+ }
1030+
1031+ public static void d(String tag, Throwable t, String msg, Object... args) {
1032+ if (LOGGING_ENABLED) Log.d(tag, format(msg, args), t);
1033+ }
1034+
1035+ public static void d(String tag, String msg, Object... args) {
1036+ d(tag, null, msg, args);
1037+ }
1038+
1039+ public static void i(String tag, Throwable t, String msg, Object... args) {
1040+ if (LOGGING_ENABLED) Log.i(tag, format(msg, args), t);
1041+ }
1042+
1043+ public static void i(String tag, String msg, Object... args) {
1044+ i(tag, null, msg, args);
1045+ }
1046+
1047+ public static void w(String tag, Throwable t, String msg, Object... args) {
1048+ if (LOGGING_ENABLED) Log.w(tag, format(msg, args), t);
1049+ }
1050+
1051+ public static void w(String tag, String msg, Object... args) {
1052+ w(tag, null, msg, args);
1053+ }
1054+
1055+ public static void e(String tag, Throwable t, String msg, Object... args) {
1056+ Log.e(tag, format(msg, args), t);
1057+ }
1058+
1059+ public static void e(String tag, String msg, Object... args) {
1060+ e(tag, null, msg, args);
1061+ }
1062+
1063+ public static void wtf(String tag, Throwable t, String msg, Object... args) {
1064+ Log.wtf(tag, format(msg, args), t);
1065+ }
1066+
1067+ public static void wtf(String tag, String msg, Object... args) {
1068+ wtf(tag, null, msg, args);
1069+ }
1070+}

Subscribers

People subscribed via source and target branches