Skip to content

Commit cf968f8

Browse files
authored
Merge pull request #66 from Iterable/feature/MOB-57-debug-level
[MOB-57] Make log level configurable from IterableConfig
2 parents 8a36790 + 6e6751a commit cf968f8

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableConfig.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.iterable.iterableapi;
22

3+
import android.util.Log;
4+
35
/**
46
*
57
*/
@@ -40,13 +42,19 @@ public class IterableConfig {
4042
*/
4143
final boolean checkForDeferredDeeplink;
4244

45+
/**
46+
* Log level for Iterable SDK log messages
47+
*/
48+
final int logLevel;
49+
4350
private IterableConfig(Builder builder) {
4451
pushIntegrationName = builder.pushIntegrationName;
4552
urlHandler = builder.urlHandler;
4653
customActionHandler = builder.customActionHandler;
4754
autoPushRegistration = builder.autoPushRegistration;
4855
legacyGCMSenderId = builder.legacyGCMSenderId;
4956
checkForDeferredDeeplink = builder.checkForDeferredDeeplink;
57+
logLevel = builder.logLevel;
5058
}
5159

5260
public static class Builder {
@@ -56,6 +64,7 @@ public static class Builder {
5664
private boolean autoPushRegistration = true;
5765
private String legacyGCMSenderId;
5866
private boolean checkForDeferredDeeplink;
67+
private int logLevel = Log.ERROR;
5968

6069
public Builder() {}
6170

@@ -119,6 +128,15 @@ public Builder setCheckForDeferredDeeplink(boolean checkForDeferredDeeplink) {
119128
return this;
120129
}
121130

131+
/**
132+
* Set the log level for Iterable SDK log messages
133+
* @param logLevel Log level, defaults to {@link Log#ERROR}
134+
*/
135+
public Builder setLogLevel(int logLevel) {
136+
this.logLevel = logLevel;
137+
return this;
138+
}
139+
122140
public IterableConfig build() {
123141
return new IterableConfig(this);
124142
}

iterableapi/src/main/java/com/iterable/iterableapi/IterableLogger.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,53 @@
88
public class IterableLogger {
99

1010
public static void d(String tag, String msg) {
11-
if (isDebugMode()) {
11+
if (isLoggableLevel(Log.DEBUG)) {
1212
Log.d(tag, msg);
1313
}
1414
}
1515

1616
public static void d(String tag, String msg, Throwable tr) {
17-
if (isDebugMode()) {
17+
if (isLoggableLevel(Log.DEBUG)) {
1818
Log.d(tag, msg, tr);
1919
}
2020
}
2121

2222
public static void w(String tag, String msg) {
23-
if (isDebugMode()) {
23+
if (isLoggableLevel(Log.WARN)) {
2424
Log.w(tag, msg);
2525
}
2626
}
2727

2828
public static void w(String tag, String msg, Throwable tr) {
29-
if (isDebugMode()) {
29+
if (isLoggableLevel(Log.WARN)) {
3030
Log.w(tag, msg, tr);
3131
}
3232
}
3333

3434
public static void e(String tag, String msg) {
35-
if (isDebugMode()) {
35+
if (isLoggableLevel(Log.ERROR)) {
3636
Log.e(tag, msg);
3737
}
3838
}
3939

4040
public static void e(String tag, String msg, Throwable tr) {
41-
if (isDebugMode()) {
41+
if (isLoggableLevel(Log.ERROR)) {
4242
Log.e(tag, msg, tr);
4343
}
4444
}
4545

46-
private static boolean isDebugMode() {
47-
return (IterableApi.sharedInstance != null) ? IterableApi.sharedInstance.getDebugMode() : false;
46+
private static boolean isLoggableLevel(int messageLevel) {
47+
return messageLevel >= getLogLevel();
48+
}
49+
50+
private static int getLogLevel() {
51+
if (IterableApi.sharedInstance != null) {
52+
if (IterableApi.sharedInstance.getDebugMode()) {
53+
return Log.VERBOSE;
54+
} else {
55+
return IterableApi.sharedInstance.config.logLevel;
56+
}
57+
}
58+
return Log.ERROR;
4859
}
4960
}

0 commit comments

Comments
 (0)