From dfa1f68283ea5335e29653ffe85541439d93f7d4 Mon Sep 17 00:00:00 2001 From: Shubham Goyal Date: Tue, 10 Dec 2024 15:16:54 +0530 Subject: [PATCH] route exception logs to logException --- src/main/java/org/commcare/util/LogTypes.java | 4 ++++ src/main/java/org/javarosa/core/api/ILogger.java | 2 ++ src/main/java/org/javarosa/core/services/Logger.java | 10 +++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/commcare/util/LogTypes.java b/src/main/java/org/commcare/util/LogTypes.java index 1b5c34bb41..16383e3d36 100644 --- a/src/main/java/org/commcare/util/LogTypes.java +++ b/src/main/java/org/commcare/util/LogTypes.java @@ -116,4 +116,8 @@ public class LogTypes { public static final String TYPE_MEDIA_EVENT = "media-event"; + /** + * A Java Exception log + */ + public static final String TYPE_EXCEPTION = "exception"; } diff --git a/src/main/java/org/javarosa/core/api/ILogger.java b/src/main/java/org/javarosa/core/api/ILogger.java index 073694c7ab..585bb4ddee 100644 --- a/src/main/java/org/javarosa/core/api/ILogger.java +++ b/src/main/java/org/javarosa/core/api/ILogger.java @@ -30,4 +30,6 @@ public interface ILogger { int logSize(); void halt(); + + void logException(Throwable e); } diff --git a/src/main/java/org/javarosa/core/services/Logger.java b/src/main/java/org/javarosa/core/services/Logger.java index d684778d54..8501fbbf7e 100644 --- a/src/main/java/org/javarosa/core/services/Logger.java +++ b/src/main/java/org/javarosa/core/services/Logger.java @@ -1,5 +1,6 @@ package org.javarosa.core.services; +import org.commcare.util.LogTypes; import org.javarosa.core.api.ILogger; import org.javarosa.core.log.FatalException; import org.javarosa.core.log.WrappedException; @@ -52,7 +53,14 @@ public static void log(String type, String message) { public static void exception(String info, Throwable e) { e.printStackTrace(); - log("exception", (info != null ? info + ": " : "") + WrappedException.printException(e)); + log(LogTypes.TYPE_EXCEPTION, (info != null ? info + ": " : "") + WrappedException.printException(e)); + if (logger != null) { + try { + logger.logException(e); + } catch (RuntimeException ex) { + logger.panic(); + } + } } public static void die(String thread, Exception e) {