Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route exception logs to logException #1453

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading