Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit 1d52257

Browse files
committed
chore: Preprend log names with java-logging
1 parent 34535a7 commit 1d52257

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

google-cloud-logging/src/main/java/com/google/cloud/logging/testing/RemoteLoggingHelper.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.io.InputStream;
2525
import java.time.Duration;
2626
import java.time.Instant;
27-
import java.time.format.DateTimeFormatter;
2827
import java.util.UUID;
2928
import java.util.logging.Level;
3029
import java.util.logging.Logger;
@@ -95,14 +94,15 @@ public static RemoteLoggingHelper create() {
9594

9695
/**
9796
* Formats a resource name for testing purpose. This method appends a random UUID to the provided
98-
* name. Prepends the Log name with the current instant time to allow for stale logs to be easily
99-
* found and removed.
97+
* name. Prepends the Log name with the `java-logging` and the current instant time to allow for
98+
* stale logs to be easily found and removed.
10099
*
101-
* <p>Format: {Instant}_{name}_{UUID}
100+
* <p>Format: java-logging_{INSTANT_IN_MILLIS}_{name}_{UUID}
102101
*/
103102
public static String formatForTest(String name) {
104-
String now = DateTimeFormatter.ISO_LOCAL_DATE.format(Instant.now());
105-
return now + "_" + name + "_" + UUID.randomUUID().toString().substring(0, 8);
103+
long nowInMillis = Instant.now().toEpochMilli();
104+
return String.format(
105+
"java-logging_%d_%s_%s", nowInMillis, name, UUID.randomUUID().toString().substring(0, 8));
106106
}
107107

108108
private static RetrySettings retrySettings() {

google-cloud-logging/src/test/java/com/google/cloud/logging/BaseSystemTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ static void beforeClass() {
5151
@AfterAll
5252
static void afterClass() throws Exception {
5353
// Use a cutoff of a day based on the log name. Any logs that were created before the cutoff
54-
// is from a previous invocation of the test and was unable to be properly deleted.
54+
// is from a previous invocation of the test and was previously unable to be properly deleted.
5555
Page<String> logPage = logging.listLogs();
5656
for (String logName : logPage.iterateAll()) {
57-
Instant cutoff = Instant.now().minus(1, ChronoUnit.DAYS);
58-
String logCreateTimeString = logName.split("_")[0];
59-
Instant logCreateTimeInstant =
60-
(Instant) DateTimeFormatter.ISO_LOCAL_DATE.parse(logCreateTimeString);
57+
if (!logName.startsWith("java-logging")) {
58+
continue;
59+
}
60+
Instant cutoff = Instant.now().minus(6, ChronoUnit.HOURS);
61+
Instant logCreateTimeInstant = Instant.ofEpochMilli(Long.parseLong(logName.split("_")[0]));
6162
if (logCreateTimeInstant.isBefore(cutoff)) {
6263
logging.deleteLog(logName);
6364
}

0 commit comments

Comments
 (0)