fix: Add flush() calls in samples (#1116) · googleapis/java-logging@6d3cb5b (original) (raw)
File tree
2 files changed
lines changed
- samples/snippets/src/main/java/com/example/logging
2 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -53,6 +53,9 @@ public static void main(String... args) throws Exception { | ||
53 | 53 | |
54 | 54 | // Writes the log entry asynchronously |
55 | 55 | logging.write(Collections.singleton(entry)); |
56 | + | |
57 | +// Optional - flush any pending log entries just before Logging is closed | |
58 | +logging.flush(); | |
56 | 59 | } |
57 | 60 | System.out.printf("Logged: %s%n", textPayload); |
58 | 61 | } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -45,7 +45,11 @@ public static void main(String[] args) throws Exception { | ||
45 | 45 | .setResource(MonitoredResource.newBuilder("global").build()) |
46 | 46 | .build(); |
47 | 47 | |
48 | +// Writes the log entry asynchronously | |
48 | 49 | logging.write(Collections.singleton(entry)); |
50 | + | |
51 | +// Optional - flush any pending log entries just before Logging is closed | |
52 | +logging.flush(); | |
49 | 53 | } |
50 | 54 | System.out.printf("Wrote to %s\n", logName); |
51 | 55 | } |