diff options
author | 2024-11-25 22:08:50 +0000 | |
---|---|---|
committer | 2024-11-25 22:08:50 +0000 | |
commit | e2f6a591c765e67d19a7b8cbe4b410638938e57a (patch) | |
tree | 9955338808b3f40b3f6a9406af5512046c58a540 /ravenwood/runtime-helper-src | |
parent | 6cf18f06f2ae89d807fbec1d36a8530f14d20fd2 (diff) | |
parent | a07975e72e50d17b8231cdab05e7cab104180da2 (diff) |
Merge "Make the log format more realistic" into main
Diffstat (limited to 'ravenwood/runtime-helper-src')
-rw-r--r-- | ravenwood/runtime-helper-src/framework/android/util/Log_ravenwood.java (renamed from ravenwood/runtime-helper-src/framework/android/util/Log_host.java) | 54 | ||||
-rw-r--r-- | ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeNative.java | 2 |
2 files changed, 45 insertions, 11 deletions
diff --git a/ravenwood/runtime-helper-src/framework/android/util/Log_host.java b/ravenwood/runtime-helper-src/framework/android/util/Log_ravenwood.java index c85bd23db893..7b26fe531e7e 100644 --- a/ravenwood/runtime-helper-src/framework/android/util/Log_host.java +++ b/ravenwood/runtime-helper-src/framework/android/util/Log_ravenwood.java @@ -18,9 +18,13 @@ package android.util; import android.util.Log.Level; import com.android.internal.os.RuntimeInit; +import com.android.ravenwood.RavenwoodRuntimeNative; import com.android.ravenwood.common.RavenwoodCommonUtils; import java.io.PrintStream; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; /** * Ravenwood "native substitution" class for {@link android.util.Log}. @@ -29,7 +33,10 @@ import java.io.PrintStream; * In order to switch to this Java implementation, uncomment the @RavenwoodNativeSubstitutionClass * annotation on {@link android.util.Log}. */ -public class Log_host { +public class Log_ravenwood { + + public static final SimpleDateFormat sTimestampFormat = + new SimpleDateFormat("MM-dd HH:mm:ss.SSS", Locale.US); public static boolean isLoggable(String tag, @Level int level) { return true; @@ -39,15 +46,6 @@ public class Log_host { if (priority < Log.INFO && !RavenwoodCommonUtils.RAVENWOOD_VERBOSE_LOGGING) { return msg.length(); // No verbose logging. } - final String buffer; - switch (bufID) { - case Log.LOG_ID_MAIN: buffer = "main"; break; - case Log.LOG_ID_RADIO: buffer = "radio"; break; - case Log.LOG_ID_EVENTS: buffer = "event"; break; - case Log.LOG_ID_SYSTEM: buffer = "system"; break; - case Log.LOG_ID_CRASH: buffer = "crash"; break; - default: buffer = "buf:" + bufID; break; - } final String prio; switch (priority) { @@ -60,8 +58,12 @@ public class Log_host { default: prio = "prio:" + priority; break; } + String leading = sTimestampFormat.format(new Date()) + + " %-6d %-6d %s %-8s: ".formatted(getPid(), getTid(), prio, tag); + var out = getRealOut(); for (String s : msg.split("\\n")) { - getRealOut().println(String.format("logd: [%s] %s %s: %s", buffer, prio, tag, s)); + out.print(leading); + out.println(s); } return msg.length(); } @@ -81,4 +83,34 @@ public class Log_host { return System.out; } } + + /** + * PID. We need to use a JNI method to get it, but JNI isn't initially ready. + * Call {@link #onRavenwoodRuntimeNativeReady} to signal when JNI is ready, at which point + * we set this field. + * (We don't want to call native methods that may not be fully initialized even with a + * try-catch, because partially initialized JNI methods could crash the process.) + */ + private static volatile int sPid = 0; + + private static ThreadLocal<Integer> sTid = + ThreadLocal.withInitial(RavenwoodRuntimeNative::gettid); + + /** + * Call it when {@link RavenwoodRuntimeNative} is usable. + */ + public static void onRavenwoodRuntimeNativeReady() { + sPid = RavenwoodRuntimeNative.getpid(); + } + + private static int getPid() { + return sPid; + } + + private static int getTid() { + if (sPid == 0) { + return 0; // Native methods not ready yet. + } + return sTid.get(); + } } diff --git a/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeNative.java b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeNative.java index 9a78989dad55..acbcdf1926db 100644 --- a/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeNative.java +++ b/ravenwood/runtime-helper-src/libcore-fake/com/android/ravenwood/RavenwoodRuntimeNative.java @@ -62,6 +62,8 @@ public class RavenwoodRuntimeNative { removeSystemProperty(null); } + public static native int getpid(); + public static native int gettid(); public static long lseek(FileDescriptor fd, long offset, int whence) throws ErrnoException { |