Skip to content

Commit

Permalink
Revert some unneeded changes to Logger done in 679e0de
Browse files Browse the repository at this point in the history
Logger was updated to get suppressed exceptions by calling `Throwable[] getSuppressed()` but `printStackTrace()` would already log them, even though shortened stacktrace with `... n more` notation, but this should be enough for debugging since main throwable stacktrace should have enough class line info. Manually logging full suppressed stacktraces would likely trigger `LOGGER_ENTRY_MAX_PAYLOAD` and split the message into multiple log entries and also duplicate the suppressed stacktraces, so best revert this unless ever necessary.
  • Loading branch information
agnostic-apollo committed Jul 1, 2021
1 parent 5c50964 commit 5a511a2
Showing 1 changed file with 13 additions and 74 deletions.
87 changes: 13 additions & 74 deletions termux-shared/src/main/java/com/termux/shared/logger/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,105 +219,54 @@ public static void logDebugAndShowToast(Context context, String message) {



public static void logStackTraceWithMessage(String tag, String message, Throwable throwable, boolean getSuppressed) {
Logger.logErrorExtended(tag, getMessageAndStackTraceString(message, throwable, getSuppressed));
}

public static void logStackTraceWithMessage(String tag, String message, Throwable throwable) {
logStackTraceWithMessage(tag, message, throwable, true);
}

public static void logStackTraceWithMessage(String message, Throwable throwable, boolean getSuppressed) {
logStackTraceWithMessage(DEFAULT_LOG_TAG, message, throwable, getSuppressed);
Logger.logErrorExtended(tag, getMessageAndStackTraceString(message, throwable));
}

public static void logStackTraceWithMessage(String message, Throwable throwable) {
logStackTraceWithMessage(DEFAULT_LOG_TAG, message, throwable, true);
}


public static void logStackTrace(String tag, Throwable throwable, boolean getSuppressed) {
logStackTraceWithMessage(tag, null, throwable, getSuppressed);
logStackTraceWithMessage(DEFAULT_LOG_TAG, message, throwable);
}

public static void logStackTrace(String tag, Throwable throwable) {
logStackTraceWithMessage(tag, null, throwable, true);
}


public static void logStackTrace(Throwable throwable, boolean getSuppressed) {
logStackTraceWithMessage(DEFAULT_LOG_TAG, null, throwable, getSuppressed);
logStackTraceWithMessage(tag, null, throwable);
}

public static void logStackTrace(Throwable throwable) {
logStackTraceWithMessage(DEFAULT_LOG_TAG, null, throwable, true);
logStackTraceWithMessage(DEFAULT_LOG_TAG, null, throwable);
}



public static void logStackTracesWithMessage(String tag, String message, List<Throwable> throwablesList, boolean getSuppressed) {
Logger.logErrorExtended(tag, getMessageAndStackTracesString(message, throwablesList, getSuppressed));
}

public static void logStackTracesWithMessage(String tag, String message, List<Throwable> throwablesList) {
Logger.logErrorExtended(tag, getMessageAndStackTracesString(message, throwablesList, true));
Logger.logErrorExtended(tag, getMessageAndStackTracesString(message, throwablesList));
}



public static String getMessageAndStackTraceString(String message, Throwable throwable) {
return getMessageAndStackTraceString(message, throwable, true);
}

public static String getMessageAndStackTraceString(String message, Throwable throwable, boolean getSuppressed) {
if (message == null && throwable == null)
return null;
else if (message != null && throwable != null)
return message + ":\n" + getStackTraceString(throwable, getSuppressed);
return message + ":\n" + getStackTraceString(throwable);
else if (throwable == null)
return message;
else
return getStackTraceString(throwable, getSuppressed);
return getStackTraceString(throwable);
}



public static String getMessageAndStackTracesString(String message, List<Throwable> throwablesList) {
return getMessageAndStackTracesString(message, throwablesList, true);
}

public static String getMessageAndStackTracesString(String message, List<Throwable> throwablesList, boolean getSuppressed) {
if (message == null && (throwablesList == null || throwablesList.size() == 0))
return null;
else if (message != null && (throwablesList != null && throwablesList.size() != 0))
return message + ":\n" + getStackTracesString(null, getStackTracesStringArray(throwablesList, getSuppressed));
return message + ":\n" + getStackTracesString(null, getStackTracesStringArray(throwablesList));
else if (throwablesList == null || throwablesList.size() == 0)
return message;
else
return getStackTracesString(null, getStackTracesStringArray(throwablesList, getSuppressed));
return getStackTracesString(null, getStackTracesStringArray(throwablesList));
}



public static String getStackTraceString(Throwable throwable, boolean getSuppressed) {
if (throwable == null) return null;

StringBuilder stackTraceString = new StringBuilder();
stackTraceString.append(getStackTraceString(throwable));

if (getSuppressed) {
Throwable[] suppressedThrowablesArray = throwable.getSuppressed();
if (suppressedThrowablesArray != null && suppressedThrowablesArray.length > 0) {
for (Throwable suppressedThrowable : suppressedThrowablesArray) {
if (suppressedThrowable == null) continue;
stackTraceString.append("\n\n").append(getStackTraceString(suppressedThrowable));
}
}
}

return stackTraceString.toString();
}

public static String getStackTraceString(Throwable throwable) {
if (throwable == null) return null;

Expand All @@ -339,25 +288,15 @@ public static String getStackTraceString(Throwable throwable) {



public static String[] getStackTracesStringArray(Throwable throwable, boolean getSuppressed) {
return getStackTracesStringArray(Collections.singletonList(throwable), getSuppressed);
}

public static String[] getStackTracesStringArray(Throwable throwable) {
return getStackTracesStringArray(Collections.singletonList(throwable), true);
return getStackTracesStringArray(Collections.singletonList(throwable));
}

public static String[] getStackTracesStringArray(List<Throwable> throwablesList) {
return getStackTracesStringArray(throwablesList, true);

}

public static String[] getStackTracesStringArray(List<Throwable> throwablesList, boolean getSuppressed) {
if (throwablesList == null) return null;

final String[] stackTraceStringArray = new String[throwablesList.size()];
for (int i = 0; i < throwablesList.size(); i++) {
stackTraceStringArray[i] = getStackTraceString(throwablesList.get(i), getSuppressed);
stackTraceStringArray[i] = getStackTraceString(throwablesList.get(i));
}
return stackTraceStringArray;
}
Expand Down Expand Up @@ -415,7 +354,7 @@ public static String getMultiLineLogStringEntry(String label, Object object, Str
else
return label + ": " + def;
}



public static void showToast(final Context context, final String toastText, boolean longDuration) {
Expand Down Expand Up @@ -444,7 +383,7 @@ public static CharSequence[] getLogLevelLabelsArray(Context context, CharSequenc
logLevelLabels[i] = getLogLevelLabel(context, Integer.parseInt(logLevels[i].toString()), addDefaultTag);
}

return logLevelLabels;
return logLevelLabels;
}

public static String getLogLevelLabel(final Context context, final int logLevel, final boolean addDefaultTag) {
Expand Down

0 comments on commit 5a511a2

Please sign in to comment.