[core] Refine module log output

* Add E/I to indicate error or information, while we are at
   it, slightly change output format.
This commit is contained in:
Wang Han 2021-03-20 16:34:10 +08:00
parent 9b081dac37
commit 40fcde9ce0
2 changed files with 11 additions and 9 deletions

View File

@ -134,7 +134,7 @@ public final class XposedBridge {
*/
public synchronized static void log(String text) {
Log.i(TAG, text);
ModuleLogger.log(text);
ModuleLogger.log(text, false);
}
/**
@ -148,7 +148,7 @@ public final class XposedBridge {
public synchronized static void log(Throwable t) {
String logStr = Log.getStackTraceString(t);
Log.e(TAG, logStr);
ModuleLogger.log(logStr);
ModuleLogger.log(logStr, true);
}
/**

View File

@ -44,23 +44,25 @@ public class ModuleLogger {
private static native void nativeLog(int fd, String logStr);
public static void log(String str) {
public static void log(String str, boolean isThrowable) {
if (fd == -1) {
Utils.logE("Logger is not initialized");
return;
}
StringBuilder sb = new StringBuilder();
String processName = ActivityThread.currentProcessName();
sb.append(logDateFormat.format(new Date()));
sb.append(' ');
sb.append(isThrowable ? "E" : "I");
sb.append('/');
sb.append(processName == null ? "?" : processName);
sb.append('(');
sb.append(Process.myPid());
sb.append('-');
sb.append(Process.myTid());
sb.append('/');
String processName = ActivityThread.currentProcessName();
if (processName == null) sb.append("?");
else sb.append(processName);
sb.append(' ');
sb.append("LSPosedBridge: ");
sb.append(')');
sb.append(": ");
sb.append(str);
sb.append('\n');
nativeLog(fd, sb.toString());