Skip to content

Commit 3c5bf7c

Browse files
📣 logger improved
1 parent e6fc87f commit 3c5bf7c

File tree

8 files changed

+66
-57
lines changed

8 files changed

+66
-57
lines changed

src/main/java/com/contentstack/sdk/CSBackgroundTask.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.contentstack.sdk;
22

33
import org.jetbrains.annotations.NotNull;
4+
45
import java.util.HashMap;
56
import java.util.LinkedHashMap;
67
import java.util.Map;
8+
import java.util.logging.Level;
79
import java.util.logging.Logger;
810

911
class CSBackgroundTask {
@@ -89,7 +91,7 @@ protected void checkHeader(@NotNull Map<String, Object> headers) {
8991
try {
9092
throw new IllegalAccessException("CSBackgroundTask Header Exception");
9193
} catch (IllegalAccessException e) {
92-
logger.severe(e.getLocalizedMessage());
94+
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
9395
}
9496
}
9597
}

src/main/java/com/contentstack/sdk/CSHttpConnection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.Iterator;
1515
import java.util.LinkedHashMap;
1616
import java.util.Map;
17+
import java.util.logging.Level;
1718
import java.util.logging.Logger;
1819

1920
import static com.contentstack.sdk.Constants.*;
@@ -175,7 +176,7 @@ public void send() {
175176
try {
176177
getService(url);
177178
} catch (IOException | JSONException e) {
178-
logger.severe(e.getLocalizedMessage());
179+
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
179180
}
180181
}
181182

src/main/java/com/contentstack/sdk/Constants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.Calendar;
77
import java.util.Date;
88
import java.util.TimeZone;
9+
import java.util.logging.Level;
910
import java.util.logging.Logger;
1011

1112
/**
@@ -89,7 +90,7 @@ public static Calendar parseDate(String date, TimeZone timeZone) {
8990
try {
9091
return parseDate(date, formatString, timeZone);
9192
} catch (ParseException e) {
92-
logger.warning(e.getLocalizedMessage());
93+
logger.log(Level.WARNING, e.getLocalizedMessage(), e);
9394
}
9495
}
9596
return null;

src/main/java/com/contentstack/sdk/EntriesModel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.util.ArrayList;
77
import java.util.List;
8+
import java.util.logging.Level;
89
import java.util.logging.Logger;
910

1011
class EntriesModel {
@@ -31,7 +32,7 @@ protected EntriesModel(JSONObject responseJSON) {
3132
}
3233
} catch (Exception e) {
3334
Logger logger = Logger.getLogger(EntriesModel.class.getSimpleName());
34-
logger.severe(e.getLocalizedMessage());
35+
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
3536
}
3637

3738
}

src/main/java/com/contentstack/sdk/Entry.java

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import retrofit2.Retrofit;
77

88
import java.util.*;
9+
import java.util.logging.Level;
910
import java.util.logging.Logger;
1011

1112
import static com.contentstack.sdk.Constants.ENVIRONMENT;
@@ -71,10 +72,10 @@ public Entry configure(JSONObject jsonObject) {
7172
* <b>Example :</b><br>
7273
*
7374
* <pre class="prettyprint">
74-
* Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
75-
* Entry entry = stack.contentType("form_name").entry("entry_uid");
76-
* entry.setHeader("custom_header_key", "custom_header_value");
77-
* </pre>
75+
* Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
76+
* Entry entry = stack.contentType("form_name").entry("entry_uid");
77+
* entry.setHeader("custom_header_key", "custom_header_value");
78+
* </pre>
7879
*/
7980

8081
public void setHeader(String key, String value) {
@@ -92,10 +93,10 @@ public void setHeader(String key, String value) {
9293
* <b>Example :</b><br>
9394
*
9495
* <pre class="prettyprint">
95-
* Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
96-
* Entry entry = stack.contentType("form_name").entry("entry_uid");
97-
* entry.removeHeader("custom_header_key");
98-
* </pre>
96+
* Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
97+
* Entry entry = stack.contentType("form_name").entry("entry_uid");
98+
* entry.removeHeader("custom_header_key");
99+
* </pre>
99100
*/
100101

101102
public void removeHeader(String key) {
@@ -243,8 +244,8 @@ public JSONObject toJSON() {
243244
* <b>Example :</b><br>
244245
*
245246
* <pre class="prettyprint">
246-
* Object obj = entry.get("key");
247-
* </pre>
247+
* Object obj = entry.get("key");
248+
* </pre>
248249
* @return Object @resultJson
249250
*/
250251
public Object get(@NotNull String key) {
@@ -260,8 +261,8 @@ public Object get(@NotNull String key) {
260261
* <b>Example :</b><br>
261262
*
262263
* <pre class="prettyprint">
263-
* String value = entry.getString("key");
264-
* </pre>
264+
* String value = entry.getString("key");
265+
* </pre>
265266
* @return String @getString
266267
*/
267268

@@ -282,8 +283,8 @@ public String getString(@NotNull String key) {
282283
* <b>Example :</b><br>
283284
*
284285
* <pre class="prettyprint">
285-
* Boolean value = entry.getBoolean("key");
286-
* </pre>
286+
* Boolean value = entry.getBoolean("key");
287+
* </pre>
287288
* @return boolean @getBoolean
288289
*/
289290

@@ -304,8 +305,8 @@ public Boolean getBoolean(@NotNull String key) {
304305
* <b>Example :</b><br>
305306
*
306307
* <pre class="prettyprint">
307-
* JSONArray value = entry.getJSONArray("key");
308-
* </pre>
308+
* JSONArray value = entry.getJSONArray("key");
309+
* </pre>
309310
* @return JSONArray @getJSONArray
310311
*/
311312

@@ -326,8 +327,8 @@ public JSONArray getJSONArray(@NotNull String key) {
326327
* <b>Example :</b><br>
327328
*
328329
* <pre class="prettyprint">
329-
* JSONObject value = entry.getJSONObject("key");
330-
* </pre>
330+
* JSONObject value = entry.getJSONObject("key");
331+
* </pre>
331332
* @return JSONObject @getJSONObject
332333
*/
333334
public JSONObject getJSONObject(@NotNull String key) {
@@ -347,8 +348,8 @@ public JSONObject getJSONObject(@NotNull String key) {
347348
* <b>Example :</b><br>
348349
*
349350
* <pre class="prettyprint">
350-
* JSONObject value = entry.getJSONObject("key");
351-
* </pre>
351+
* JSONObject value = entry.getJSONObject("key");
352+
* </pre>
352353
* @return Number @getNumber
353354
*/
354355

@@ -369,8 +370,8 @@ public Number getNumber(@NotNull String key) {
369370
* <b>Example :</b><br>
370371
*
371372
* <pre class="prettyprint">
372-
* int value = entry.getInt("key");
373-
* </pre>
373+
* int value = entry.getInt("key");
374+
* </pre>
374375
* @return int @getInt
375376
*/
376377

@@ -435,8 +436,8 @@ public double getDouble(@NotNull String key) {
435436
* <b>Example :</b><br>
436437
*
437438
* <pre class="prettyprint">
438-
* long value = entry.getLong("key");
439-
* </pre>
439+
* long value = entry.getLong("key");
440+
* </pre>
440441
* @return long @getLong
441442
*/
442443

@@ -459,8 +460,8 @@ public long getLong(@NotNull String key) {
459460
* <b>Example :</b><br>
460461
*
461462
* <pre class="prettyprint">
462-
* short value = entry.getShort("key");
463-
* </pre>
463+
* short value = entry.getShort("key");
464+
* </pre>
464465
* @return short @getShort
465466
*/
466467
public short getShort(@NotNull String key) {
@@ -480,8 +481,8 @@ public short getShort(@NotNull String key) {
480481
* <b>Example :</b><br>
481482
*
482483
* <pre class="prettyprint">
483-
* Calendar value = entry.getDate("key");
484-
* </pre>
484+
* Calendar value = entry.getDate("key");
485+
* </pre>
485486
* @return Calendar @getDate
486487
*/
487488

@@ -490,7 +491,7 @@ public Calendar getDate(@NotNull String key) {
490491
String value = getString(key);
491492
return Constants.parseDate(value, null);
492493
} catch (Exception e) {
493-
logger.severe(e.getLocalizedMessage());
494+
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
494495
}
495496
return null;
496497
}
@@ -512,7 +513,7 @@ public Calendar getCreateAt() {
512513
String value = getString("created_at");
513514
return Constants.parseDate(value, null);
514515
} catch (Exception e) {
515-
logger.severe(e.getLocalizedMessage());
516+
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
516517
}
517518
return null;
518519
}
@@ -549,7 +550,7 @@ public Calendar getUpdateAt() {
549550
String value = getString("updated_at");
550551
return Constants.parseDate(value, null);
551552
} catch (Exception e) {
552-
logger.severe(e.getLocalizedMessage());
553+
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
553554
}
554555
return null;
555556
}
@@ -588,7 +589,7 @@ public Calendar getDeleteAt() {
588589
String value = getString("deleted_at");
589590
return Constants.parseDate(value, null);
590591
} catch (Exception e) {
591-
logger.severe(e.getLocalizedMessage());
592+
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
592593
}
593594
return null;
594595
}
@@ -663,9 +664,9 @@ public List<Asset> getAssets(String key) {
663664
* <b>Example :</b><br>
664665
*
665666
* <pre class="prettyprint">
666-
* Group innerGroup = entry.getGroup("key");
667-
* return null
668-
* </pre>
667+
* Group innerGroup = entry.getGroup("key");
668+
* return null
669+
* </pre>
669670
* @return {@link Group}
670671
*/
671672
public Group getGroup(String key) {
@@ -749,7 +750,7 @@ public ArrayList<Entry> getAllEntries(String refKey, String refContentType) {
749750
entryInstance = contentType.stackInstance.contentType(refContentType).entry();
750751
} catch (Exception e) {
751752
entryInstance = new Entry(refContentType);
752-
logger.severe(e.getLocalizedMessage());
753+
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
753754
}
754755
entryInstance.setUid(model.uid);
755756
entryInstance.resultJson = model.jsonObject;
@@ -946,24 +947,24 @@ public Entry exceptWithReferenceUid(@NotNull ArrayList<String> fieldUid, @NotNul
946947
* <b>Example :</b><br>
947948
*
948949
* <pre class="prettyprint">
949-
* {@code
950-
* Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
951-
* Entry entry = stack.contentType("form_name").entry("entry_uid");<br>
952-
* entry.fetch(new EntryResultCallBack() {<br>
953-
* &#64;Override
954-
* public void onCompletion(ResponseType responseType, Error error) {
955-
* }<br>
956-
* });<br>
957-
* }
958-
* </pre>
950+
* {@code
951+
* Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
952+
* Entry entry = stack.contentType("form_name").entry("entry_uid");<br>
953+
* entry.fetch(new EntryResultCallBack() {<br>
954+
* &#64;Override
955+
* public void onCompletion(ResponseType responseType, Error error) {
956+
* }<br>
957+
* });<br>
958+
* }
959+
* </pre>
959960
*/
960961

961962
public void fetch(EntryResultCallBack callback) {
962963
if (uid.isEmpty()) { // throws IllegalAccessException if uid is Empty
963964
try {
964965
throw new IllegalAccessException("Entry Uid is required");
965966
} catch (IllegalAccessException e) {
966-
logger.severe(e.getLocalizedMessage());
967+
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
967968
}
968969
}
969970
String urlString = "content_types/" + contentTypeUid + "/entries/" + uid;

src/main/java/com/contentstack/sdk/Group.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.ArrayList;
77
import java.util.Calendar;
88
import java.util.List;
9+
import java.util.logging.Level;
910
import java.util.logging.Logger;
1011

1112
public class Group {
@@ -286,7 +287,7 @@ public Calendar getDate(String key) {
286287
String value = getString(key);
287288
return Constants.parseDate(value, null);
288289
} catch (Exception e) {
289-
logger.severe(e.getLocalizedMessage());
290+
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
290291
}
291292
return null;
292293
}
@@ -407,7 +408,7 @@ public ArrayList<Entry> getAllEntries(String refKey, String refContentType) {
407408
entryInstance = stackInstance.contentType(refContentType).entry();
408409
} catch (Exception e) {
409410
entryInstance = new Entry(refContentType);
410-
logger.severe(e.getLocalizedMessage());
411+
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
411412
}
412413
entryInstance.setUid(model.uid);
413414
entryInstance.resultJson = model.jsonObject;
@@ -418,7 +419,7 @@ public ArrayList<Entry> getAllEntries(String refKey, String refContentType) {
418419
}
419420
}
420421
} catch (Exception e) {
421-
logger.severe(e.getLocalizedMessage());
422+
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
422423
return entryContainer;
423424
}
424425
return entryContainer;

src/main/java/com/contentstack/sdk/Query.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.json.JSONObject;
66

77
import java.util.*;
8+
import java.util.logging.Level;
89
import java.util.logging.Logger;
910

1011
import static com.contentstack.sdk.Constants.*;
@@ -1195,7 +1196,7 @@ private void throwException(String queryName, String messageString, Exception e)
11951196
errorHashMap.put(queryName, e.getLocalizedMessage());
11961197
}
11971198
errorHashMap.put("detail", messageString);
1198-
logger.warning(messageString);
1199+
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
11991200
}
12001201

12011202
protected void setQueryJson() {
@@ -1235,7 +1236,7 @@ protected void execQuery(SingleQueryResultCallback callBack, QueryResultsCallBac
12351236
mainJSON.put(QUERY, urlQueries);
12361237
fetchFromNetwork(urlString, mainJSON, callback, callBack);
12371238
} catch (Exception e) {
1238-
logger.severe(e.getLocalizedMessage());
1239+
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
12391240
throwException("find", Constants.QUERY_EXCEPTION, e);
12401241
}
12411242

src/main/java/com/contentstack/sdk/QueryResult.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.json.JSONObject;
55

66
import java.util.List;
7+
import java.util.logging.Level;
78
import java.util.logging.Logger;
89

910
public class QueryResult {
@@ -108,7 +109,7 @@ protected void setJSON(JSONObject jsonobject, List<Entry> objectList) {
108109
}
109110

110111
} catch (Exception e) {
111-
logger.severe(e.getLocalizedMessage());
112+
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
112113
}
113114
}
114115

0 commit comments

Comments
 (0)