Skip to content

Commit

Permalink
Merge pull request #1453 from dimagi/reportNonFatals
Browse files Browse the repository at this point in the history
Route exception logs to logException
  • Loading branch information
avazirna authored Dec 12, 2024
2 parents 25a9317 + dfa1f68 commit 7d747e3
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 7d747e3

Please sign in to comment.