mirror of
https://github.com/revanced/revanced-patches.git
synced 2025-06-13 05:37:41 +02:00
refactor(YouTube - Enabling debugging): Adjust logger formatting to preserve backwards compatibility (#5054)
This commit is contained in:

committed by
GitHub

parent
80f50e8c50
commit
ef21efa0e8
@ -41,7 +41,10 @@ public class Logger {
|
|||||||
ERROR
|
ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String REVANCED_LOG_TAG = "revanced";
|
/**
|
||||||
|
* Log tag prefix. Only used for system logging.
|
||||||
|
*/
|
||||||
|
private static final String REVANCED_LOG_TAG_PREFIX = "revanced: ";
|
||||||
|
|
||||||
private static final String LOGGER_CLASS_NAME = Logger.class.getName();
|
private static final String LOGGER_CLASS_NAME = Logger.class.getName();
|
||||||
|
|
||||||
@ -90,17 +93,13 @@ public class Logger {
|
|||||||
String messageString = message.buildMessageString();
|
String messageString = message.buildMessageString();
|
||||||
String className = getOuterClassSimpleName(message);
|
String className = getOuterClassSimpleName(message);
|
||||||
|
|
||||||
StringBuilder logBuilder = new StringBuilder(className.length() + 2
|
String logText = messageString;
|
||||||
+ messageString.length());
|
|
||||||
logBuilder.append(className).append(": ").append(messageString);
|
|
||||||
|
|
||||||
String toastMessage = showToast ? logBuilder.toString() : null;
|
|
||||||
|
|
||||||
// Append exception message if present.
|
// Append exception message if present.
|
||||||
if (ex != null) {
|
if (ex != null) {
|
||||||
var exceptionMessage = ex.getMessage();
|
var exceptionMessage = ex.getMessage();
|
||||||
if (exceptionMessage != null) {
|
if (exceptionMessage != null) {
|
||||||
logBuilder.append("\nException: ").append(exceptionMessage);
|
logText += "\nException: " + exceptionMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,29 +110,31 @@ public class Logger {
|
|||||||
// Remove the stacktrace elements of this class.
|
// Remove the stacktrace elements of this class.
|
||||||
final int loggerIndex = stackTrace.lastIndexOf(LOGGER_CLASS_NAME);
|
final int loggerIndex = stackTrace.lastIndexOf(LOGGER_CLASS_NAME);
|
||||||
final int loggerBegins = stackTrace.indexOf('\n', loggerIndex);
|
final int loggerBegins = stackTrace.indexOf('\n', loggerIndex);
|
||||||
logBuilder.append(stackTrace, loggerBegins, stackTrace.length());
|
logText += stackTrace.substring(loggerBegins);
|
||||||
}
|
}
|
||||||
|
|
||||||
String logText = logBuilder.toString();
|
// Do not include "revanced:" prefix in clipboard logs.
|
||||||
LogBufferManager.appendToLogBuffer(logText);
|
String managerToastString = className + ": " + logText;
|
||||||
|
LogBufferManager.appendToLogBuffer(managerToastString);
|
||||||
|
|
||||||
|
String logTag = REVANCED_LOG_TAG_PREFIX + className;
|
||||||
switch (logLevel) {
|
switch (logLevel) {
|
||||||
case DEBUG:
|
case DEBUG:
|
||||||
if (ex == null) Log.d(REVANCED_LOG_TAG, logText);
|
if (ex == null) Log.d(logTag, logText);
|
||||||
else Log.d(REVANCED_LOG_TAG, logText, ex);
|
else Log.d(logTag, logText, ex);
|
||||||
break;
|
break;
|
||||||
case INFO:
|
case INFO:
|
||||||
if (ex == null) Log.i(REVANCED_LOG_TAG, logText);
|
if (ex == null) Log.i(logTag, logText);
|
||||||
else Log.i(REVANCED_LOG_TAG, logText, ex);
|
else Log.i(logTag, logText, ex);
|
||||||
break;
|
break;
|
||||||
case ERROR:
|
case ERROR:
|
||||||
if (ex == null) Log.e(REVANCED_LOG_TAG, logText);
|
if (ex == null) Log.e(logTag, logText);
|
||||||
else Log.e(REVANCED_LOG_TAG, logText, ex);
|
else Log.e(logTag, logText, ex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toastMessage != null) {
|
if (showToast) {
|
||||||
Utils.showToastLong(toastMessage);
|
Utils.showToastLong(managerToastString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user