Skip to content

Commit 1eb6c32

Browse files
committed
added error logging to Logger
1 parent d6918cd commit 1eb6c32

File tree

6 files changed

+23
-10
lines changed

6 files changed

+23
-10
lines changed

core/src/main/java/io/snabble/sdk/Events.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,6 @@ public EventType getEventType() {
295295
}
296296

297297
public static void logErrorEvent(String projectId, String format, Object... args) {
298-
Logger.d(format, args);
299-
300298
// since we have no error logging without a project, we try to find the project by id
301299
// and if no project is found we just use the first project to at least log it to something
302300
Project project = Snabble.getInstance().getProjectById(projectId);

core/src/main/java/io/snabble/sdk/Snabble.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public void setup(Application app, Config config, final SetupCompletionListener
8686
this.application = app;
8787
this.config = config;
8888

89+
Logger.setErrorEventHandler((message, args) -> Events.logErrorEvent(null, message, args));
90+
8991
if (config.appId == null || config.secret == null) {
9092
setupCompletionListener.onError(Error.CONFIG_PARAMETER_MISSING);
9193
return;

core/src/main/java/io/snabble/sdk/payment/PaymentCredentials.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,13 @@ public boolean validate() {
568568
if (type == Type.CREDIT_CARD_PSD2) {
569569
Date date = new Date(validTo);
570570
if (date.getTime() < System.currentTimeMillis()) {
571-
Events.logErrorEvent(null, "removing payment credentials: expired");
571+
Logger.errorEvent(null, "removing payment credentials: expired");
572572
return false;
573573
}
574574
}
575575

576576
if (type == Type.CREDIT_CARD) {
577-
Events.logErrorEvent(null, "removing payment credentials: old credit card type");
577+
Logger.errorEvent(null, "removing payment credentials: old credit card type");
578578
return false;
579579
}
580580

@@ -585,7 +585,7 @@ public boolean validate() {
585585
}
586586
}
587587

588-
Events.logErrorEvent(null, "removing payment credentials: different gateway certificate signature");
588+
Logger.errorEvent(null, "removing payment credentials: different gateway certificate signature");
589589
return false;
590590
}
591591

core/src/main/java/io/snabble/sdk/payment/PaymentCredentialsStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public void removeInvalidCredentials() {
181181
Snabble snabble = Snabble.getInstance();
182182
if (snabble.getProjects().size() > 0) {
183183
if (removals.size() > 0) {
184-
Events.logErrorEvent(null, "Deleted payment credentials because device is not secure anymore. Lost access to %d payment credentials", removals.size());
184+
Logger.errorEvent(null, "Deleted payment credentials because device is not secure anymore. Lost access to %d payment credentials", removals.size());
185185
}
186186
}
187187
}

utils/src/main/java/io/snabble/sdk/utils/Logger.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class Logger {
1313
private static final int CALL_STACK_INDEX = 2;
1414

1515
private static boolean isEnabled = BuildConfig.DEBUG;
16+
private static ErrorEventHandler errorEventHandler = null;
1617

1718
public static void setEnabled(boolean enable) {
1819
isEnabled = enable;
@@ -85,4 +86,19 @@ public static void v(String message, Object... args) {
8586
}
8687
}
8788
}
89+
90+
public interface ErrorEventHandler {
91+
void logErrorEvent(String message, Object... args);
92+
}
93+
94+
public static void setErrorEventHandler(ErrorEventHandler e) {
95+
errorEventHandler = e;
96+
}
97+
98+
public static void errorEvent(String message, Object... args) {
99+
ErrorEventHandler e = errorEventHandler;
100+
if (e != null) {
101+
e.logErrorEvent(message, args);
102+
}
103+
}
88104
}

utils/src/main/java/io/snabble/sdk/utils/security/KeyStoreCipherMarshmallow.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,10 @@ private boolean isKeyAccessible() {
8989
Key key = keyStore.getKey(alias, null);
9090
c.init(Cipher.ENCRYPT_MODE, key, ivParameterSpec);
9191
return true;
92-
} catch (KeyPermanentlyInvalidatedException e) {
93-
Logger.d("KeyPermanentlyInvalidatedException: " + e.getMessage());
94-
return false;
9592
} catch (UserNotAuthenticatedException e) {
9693
return true;
9794
} catch (Exception e) {
98-
Logger.d(e.getClass().getName() + ": " + e.getMessage());
95+
Logger.errorEvent("KeyStore inaccessible: " + e.getClass().getName() + ": " + e.getMessage());
9996
return false;
10097
}
10198
}

0 commit comments

Comments
 (0)