From c4b75122e70d31e9717c89be7c2bdef39fc37fff Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Mon, 15 Nov 2021 17:23:10 +0000 Subject: [PATCH] Use ISO 8601 format for LocalLog local timestamps Change to using ISO 8601 duration formatting for LocalLog local timestamps, which makes it consistent with other time / time zone detection dumpsys for easier comparison. LocalLog is used by NetworkStack code as a standalone library, so therefore has to depend on public SDK APIs, hence the use of Duration. The local timestamp logging mode is only currently used for time / time zone detection, which is low-frequency logging. Bug: 204855374 Test: atest core/tests/coretests/src/android/util/LocalLogTest.java Change-Id: Idce0d39c59670facdf48deca852b862ff0d71991 --- core/java/android/util/LocalLog.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/java/android/util/LocalLog.java b/core/java/android/util/LocalLog.java index 8c4dcb3b28e2b..cd077e1f756c6 100644 --- a/core/java/android/util/LocalLog.java +++ b/core/java/android/util/LocalLog.java @@ -22,6 +22,7 @@ import android.os.SystemClock; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.time.Duration; import java.time.Instant; import java.time.LocalDateTime; import java.util.ArrayDeque; @@ -63,7 +64,8 @@ public final class LocalLog { if (mUseLocalTimestamps) { logLine = LocalDateTime.now() + " - " + msg; } else { - logLine = SystemClock.elapsedRealtime() + " / " + Instant.now() + " - " + msg; + logLine = Duration.ofMillis(SystemClock.elapsedRealtime()) + + " / " + Instant.now() + " - " + msg; } append(logLine); }