Skip to content

Commit

Permalink
route exception logs to logException
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham1g5 committed Dec 10, 2024
1 parent 25a9317 commit dfa1f68
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/org/commcare/util/LogTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
2 changes: 2 additions & 0 deletions src/main/java/org/javarosa/core/api/ILogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ public interface ILogger {
int logSize();

void halt();

void logException(Throwable e);
}
10 changes: 9 additions & 1 deletion src/main/java/org/javarosa/core/services/Logger.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit dfa1f68

Please sign in to comment.