From 8cf2024a2ce857593efa4e3c885890649ffd568c Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Wed, 16 Feb 2022 22:07:47 -0500 Subject: [PATCH 01/12] docs(sample): Add sample for Native Image support --- samples/native-image-sample/README.md | 71 +++++++++ samples/native-image-sample/pom.xml | 148 ++++++++++++++++++ .../logging/NativeImageLoggingSample.java | 60 +++++++ .../logging/ITNativeImageLoggingSample.java | 47 ++++++ samples/pom.xml | 1 + 5 files changed, 327 insertions(+) create mode 100644 samples/native-image-sample/README.md create mode 100644 samples/native-image-sample/pom.xml create mode 100644 samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java create mode 100644 samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java diff --git a/samples/native-image-sample/README.md b/samples/native-image-sample/README.md new file mode 100644 index 000000000..398a55e83 --- /dev/null +++ b/samples/native-image-sample/README.md @@ -0,0 +1,71 @@ +# Cloud Logging Client Libraries with Native Image + +This application uses the Google Cloud [Logging Client Libraries](https://github.com/googleapis/java-logging) and can be compiled with Native Image Native Image. + +## Setup Instructions + +You will need to follow these prerequisite steps in order to run the samples: + +1. If you have not already, [create a Google Cloud Platform Project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_project). + +2. Install the [Google Cloud SDK](https://cloud.google.com/sdk/) which will allow you to run the sample with your project's credentials. + + Once installed, log in with Application Default Credentials using the following command: + + ``` + gcloud auth application-default login + ``` + + **Note:** Authenticating with Application Default Credentials is convenient to use during development, but we recommend [alternate methods of authentication](https://cloud.google.com/docs/authentication/production) during production use. + +3. Install the GraalVM compiler. + + You can follow the [official installation instructions](https://www.graalvm.org/docs/getting-started/#install-graalvm) from the GraalVM website. + After following the instructions, ensure that you install the native image extension installed by running: + + ``` + gu install native-image + ``` + + Once you finish following the instructions, verify that the default version of Java is set to the GraalVM version by running `java -version` in a terminal. + + You will see something similar to the below output: + + ``` + $ java -version + + openjdk version "11.0.7" 2020-04-14 + OpenJDK Runtime Environment GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02) + OpenJDK 64-Bit Server VM GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02, mixed mode, sharing) + ``` + +4. Enable the [Logging APIs](https://console.cloud.google.com/flows/enableapi?apiid=logging.googleapis.com). + +## Sample + +Navigate to this directory in a new terminal. + +1. Compile the application using the Native Image Compiler. This step may take a few minutes. + + ``` + mvn package -P native -DskipTests + ``` + +2. Run the application: + + ``` + ./target/native-image-sample + ``` + +3. The application will log a message to your local terminal and to Google Cloud Console. + + Navigate to the [Cloud Console Logs Viewer](https://console.cloud.google.com/logs/viewer) to view you logs and find the newly generated log entry in Cloud Console: + ``` + This is a log produced by Native Image. + ``` +### Sample Integration test with Native Image Support +In order to run the sample integration test as a native image, call the following command: + + ``` + mvn test -Pnative + ``` \ No newline at end of file diff --git a/samples/native-image-sample/pom.xml b/samples/native-image-sample/pom.xml new file mode 100644 index 000000000..162c7df07 --- /dev/null +++ b/samples/native-image-sample/pom.xml @@ -0,0 +1,148 @@ + + + + 4.0.0 + com.example.logging + native-image-sample + Native Image Sample + https://github.com/googleapis/java-logging + + + + com.google.cloud.samples + shared-configuration + 1.2.0 + + + + 11 + 11 + UTF-8 + + + + + + com.google.cloud + libraries-bom + 24.3.0 + pom + import + + + + + + + com.google.cloud + google-cloud-logging + + + + junit + junit + 4.13.2 + test + + + com.google.truth + truth + 1.1.3 + test + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + com.example.logging.NativeImageLoggingSample + + + + + + + + + + + + native + + + + com.google.cloud + native-image-support + 0.12.0 + + + org.junit.vintage + junit-vintage-engine + 5.8.2 + test + + + org.graalvm.buildtools + junit-platform-native + 0.9.9 + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + 2.22.2 + + + **/IT* + + + + + org.graalvm.buildtools + native-maven-plugin + 0.9.9 + true + + com.example.logging.NativeImageLoggingSample + + + --no-fallback + --no-server + + + + + build-native + + build + test + + package + + + test-native + + test + + test + + + + + + + + \ No newline at end of file diff --git a/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java b/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java new file mode 100644 index 000000000..496d5ca28 --- /dev/null +++ b/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java @@ -0,0 +1,60 @@ +/* + * Copyright 2020-2021 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.logging; + +import com.google.cloud.MonitoredResource; +import com.google.cloud.logging.LogEntry; +import com.google.cloud.logging.Logging; +import com.google.cloud.logging.LoggingOptions; +import com.google.cloud.logging.Payload.StringPayload; +import com.google.cloud.logging.Severity; +import java.util.Collections; + +/** + * Basic sample application which writes a log message to Cloud Logging. + */ +public class NativeImageLoggingSample { + + /** + * Runs the Logging Sample Application. + */ + public static void main(String[] args) { + // Instantiates a client + Logging client = LoggingOptions.getDefaultInstance().getService(); + + // The name of the log to write to + String logName = "nativeimage_logging_sample.log"; + + // The data to write to the log + String text = "This is a log produced by Native Image."; + + LogEntry entry = LogEntry.newBuilder(StringPayload.of(text)) + .setSeverity(Severity.INFO) + .setLogName(logName) + .setResource(MonitoredResource.newBuilder("global").build()) + .build(); + + client.write(Collections.singleton(entry)); + client.flush(); + + System.out.println(String.format("Logged: %s", text)); + System.out.println("Log message written to Cloud Logging."); + System.out.println( + "See your logs in the Cloud Console: https://console.cloud.google.com/logs/viewer " + + "(Might take a few seconds to load.)"); + } +} \ No newline at end of file diff --git a/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java b/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java new file mode 100644 index 000000000..524df68bb --- /dev/null +++ b/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.logging; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.cloud.logging.Logging; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import org.junit.Before; +import org.junit.Test; + +public class ITNativeImageLoggingSample { + + private ByteArrayOutputStream bout; + private PrintStream out; + private static Logging logging; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @Test + public void testLogging() { + bout.reset(); + NativeImageLoggingSample.main(new String[]{}); + String output = bout.toString(); + assertThat(output).contains("Logged: This is a log produced by Native Image."); + } +} \ No newline at end of file diff --git a/samples/pom.xml b/samples/pom.xml index 237eacb00..1431af7d1 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -31,6 +31,7 @@ snapshot install-without-bom snippets + native-image-sample From d4ada9c00b33ea5ddd05340d806389e726ce137b Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Thu, 24 Feb 2022 12:44:31 -0500 Subject: [PATCH 02/12] report duration for sample --- .../java/com/example/logging/NativeImageLoggingSample.java | 6 ++++++ .../com/example/logging/ITNativeImageLoggingSample.java | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java b/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java index 496d5ca28..3d0479b99 100644 --- a/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java +++ b/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java @@ -22,6 +22,8 @@ import com.google.cloud.logging.LoggingOptions; import com.google.cloud.logging.Payload.StringPayload; import com.google.cloud.logging.Severity; +import java.time.Duration; +import java.time.Instant; import java.util.Collections; /** @@ -33,6 +35,7 @@ public class NativeImageLoggingSample { * Runs the Logging Sample Application. */ public static void main(String[] args) { + Instant startTime = Instant.now(); // Instantiates a client Logging client = LoggingOptions.getDefaultInstance().getService(); @@ -56,5 +59,8 @@ public static void main(String[] args) { System.out.println( "See your logs in the Cloud Console: https://console.cloud.google.com/logs/viewer " + "(Might take a few seconds to load.)"); + Instant endTime = Instant.now(); + Duration duration = Duration.between(startTime, endTime); + System.out.println("Duration: " + duration.toString()); } } \ No newline at end of file diff --git a/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java b/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java index 524df68bb..2f53f690b 100644 --- a/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java +++ b/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java @@ -18,7 +18,6 @@ import static com.google.common.truth.Truth.assertThat; -import com.google.cloud.logging.Logging; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import org.junit.Before; @@ -28,7 +27,6 @@ public class ITNativeImageLoggingSample { private ByteArrayOutputStream bout; private PrintStream out; - private static Logging logging; @Before public void setUp() { From c433d649a17040e7314658682969cea3a0773c46 Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Thu, 24 Feb 2022 12:46:25 -0500 Subject: [PATCH 03/12] minor clean up of pom.xml --- samples/native-image-sample/pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samples/native-image-sample/pom.xml b/samples/native-image-sample/pom.xml index 162c7df07..82ed169d1 100644 --- a/samples/native-image-sample/pom.xml +++ b/samples/native-image-sample/pom.xml @@ -63,8 +63,7 @@ - com.example.logging.NativeImageLoggingSample - + com.example.logging.NativeImageLoggingSample From f63dd154501a0c5fac3ae185078787bf1df4ef32 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 24 Feb 2022 17:50:22 +0000 Subject: [PATCH 04/12] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 5 +++-- .../logging/NativeImageLoggingSample.java | 21 ++++++++----------- .../logging/ITNativeImageLoggingSample.java | 4 ++-- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 224a7a95d..24d78ae8a 100644 --- a/README.md +++ b/README.md @@ -58,13 +58,13 @@ implementation 'com.google.cloud:google-cloud-logging' If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-logging:3.6.2' +implementation 'com.google.cloud:google-cloud-logging:3.6.4' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-logging" % "3.6.2" +libraryDependencies += "com.google.cloud" % "google-cloud-logging" % "3.6.4" ``` ## Authentication @@ -302,6 +302,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-logging/tree/ | Sample | Source Code | Try it | | --------------------------- | --------------------------------- | ------ | +| Native Image Logging Sample | [source code](https://github.com/googleapis/java-logging/blob/main/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-logging&page=editor&open_in_editor=samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java) | | Get Sink Metadata | [source code](https://github.com/googleapis/java-logging/blob/main/samples/snippets/src/main/java/com/example/logging/GetSinkMetadata.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-logging&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/logging/GetSinkMetadata.java) | | List Log Entries | [source code](https://github.com/googleapis/java-logging/blob/main/samples/snippets/src/main/java/com/example/logging/ListLogEntries.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-logging&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/logging/ListLogEntries.java) | | List Logs | [source code](https://github.com/googleapis/java-logging/blob/main/samples/snippets/src/main/java/com/example/logging/ListLogs.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-logging&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/logging/ListLogs.java) | diff --git a/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java b/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java index 3d0479b99..acf677ca6 100644 --- a/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java +++ b/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java @@ -26,14 +26,10 @@ import java.time.Instant; import java.util.Collections; -/** - * Basic sample application which writes a log message to Cloud Logging. - */ +/** Basic sample application which writes a log message to Cloud Logging. */ public class NativeImageLoggingSample { - /** - * Runs the Logging Sample Application. - */ + /** Runs the Logging Sample Application. */ public static void main(String[] args) { Instant startTime = Instant.now(); // Instantiates a client @@ -45,11 +41,12 @@ public static void main(String[] args) { // The data to write to the log String text = "This is a log produced by Native Image."; - LogEntry entry = LogEntry.newBuilder(StringPayload.of(text)) - .setSeverity(Severity.INFO) - .setLogName(logName) - .setResource(MonitoredResource.newBuilder("global").build()) - .build(); + LogEntry entry = + LogEntry.newBuilder(StringPayload.of(text)) + .setSeverity(Severity.INFO) + .setLogName(logName) + .setResource(MonitoredResource.newBuilder("global").build()) + .build(); client.write(Collections.singleton(entry)); client.flush(); @@ -63,4 +60,4 @@ public static void main(String[] args) { Duration duration = Duration.between(startTime, endTime); System.out.println("Duration: " + duration.toString()); } -} \ No newline at end of file +} diff --git a/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java b/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java index 2f53f690b..a26489a35 100644 --- a/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java +++ b/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java @@ -38,8 +38,8 @@ public void setUp() { @Test public void testLogging() { bout.reset(); - NativeImageLoggingSample.main(new String[]{}); + NativeImageLoggingSample.main(new String[] {}); String output = bout.toString(); assertThat(output).contains("Logged: This is a log produced by Native Image."); } -} \ No newline at end of file +} From 7a7d5adf9a9dfdd7a124211ae702e427bf42bf4e Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Mon, 28 Feb 2022 20:58:23 -0500 Subject: [PATCH 05/12] fix copyright and add support for standard java --- samples/native-image-sample/pom.xml | 26 +++++++++++++++++-- .../logging/NativeImageLoggingSample.java | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/samples/native-image-sample/pom.xml b/samples/native-image-sample/pom.xml index 82ed169d1..59c72c382 100644 --- a/samples/native-image-sample/pom.xml +++ b/samples/native-image-sample/pom.xml @@ -56,18 +56,41 @@ + org.apache.maven.plugins maven-jar-plugin + 3.2.2 + true + dependency-jars/ com.example.logging.NativeImageLoggingSample + + org.apache.maven.plugins + maven-dependency-plugin + 3.2.0 + + + copy-dependencies + package + + copy-dependencies + + + + ${project.build.directory}/dependency-jars/ + + + + + @@ -115,8 +138,7 @@ 0.9.9 true - com.example.logging.NativeImageLoggingSample - + com.example.logging.NativeImageLoggingSample --no-fallback --no-server diff --git a/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java b/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java index 3d0479b99..50d64333a 100644 --- a/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java +++ b/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 Google LLC + * Copyright 2022 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From a59628ce87119ae1ba05a908c50cfdbd890255c8 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 1 Mar 2022 02:06:29 +0000 Subject: [PATCH 06/12] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 24d78ae8a..c68783c7d 100644 --- a/README.md +++ b/README.md @@ -58,13 +58,13 @@ implementation 'com.google.cloud:google-cloud-logging' If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-logging:3.6.4' +implementation 'com.google.cloud:google-cloud-logging:3.7.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-logging" % "3.6.4" +libraryDependencies += "com.google.cloud" % "google-cloud-logging" % "3.7.0" ``` ## Authentication From ef74a47a6aeee2a8a2f0cd15a8fa203565b7b39e Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Thu, 3 Mar 2022 10:11:01 -0500 Subject: [PATCH 07/12] native-sample --- samples/native-image-sample/pom.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/native-image-sample/pom.xml b/samples/native-image-sample/pom.xml index 59c72c382..afc30a7ec 100644 --- a/samples/native-image-sample/pom.xml +++ b/samples/native-image-sample/pom.xml @@ -18,8 +18,9 @@ - 11 - 11 + + 1.8 + 1.8 UTF-8 From 9fd5af2202dced8968cfdbfa7b743bf4aff0852d Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 3 Mar 2022 15:14:03 +0000 Subject: [PATCH 08/12] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 87d2287a0..601d44e3b 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ If you are using Maven without BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies ```Groovy -implementation platform('com.google.cloud:libraries-bom:24.3.0') +implementation platform('com.google.cloud:libraries-bom:24.4.0') implementation 'com.google.cloud:google-cloud-logging' ``` From d96095d2a7823b7ab827f19c9abd2a0605936349 Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Fri, 4 Mar 2022 17:14:58 -0500 Subject: [PATCH 09/12] ensure that Logging client is closed after sample finishes running --- .../java/com/example/logging/NativeImageLoggingSample.java | 3 ++- .../java/com/example/logging/ITNativeImageLoggingSample.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java b/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java index 8f0d6fbcc..6fa688060 100644 --- a/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java +++ b/samples/native-image-sample/src/main/java/com/example/logging/NativeImageLoggingSample.java @@ -30,7 +30,7 @@ public class NativeImageLoggingSample { /** Runs the Logging Sample Application. */ - public static void main(String[] args) { + public static void main(String[] args) throws Exception { Instant startTime = Instant.now(); // Instantiates a client Logging client = LoggingOptions.getDefaultInstance().getService(); @@ -50,6 +50,7 @@ public static void main(String[] args) { client.write(Collections.singleton(entry)); client.flush(); + client.close(); System.out.println(String.format("Logged: %s", text)); System.out.println("Log message written to Cloud Logging."); diff --git a/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java b/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java index a26489a35..1708174bd 100644 --- a/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java +++ b/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java @@ -36,7 +36,7 @@ public void setUp() { } @Test - public void testLogging() { + public void testLogging() throws Exception { bout.reset(); NativeImageLoggingSample.main(new String[] {}); String output = bout.toString(); From 9b4e47759817a7120bfb318647bf2fb907c1802a Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 4 Mar 2022 22:17:38 +0000 Subject: [PATCH 10/12] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 601d44e3b..dfaddfffe 100644 --- a/README.md +++ b/README.md @@ -58,13 +58,13 @@ implementation 'com.google.cloud:google-cloud-logging' If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-logging:3.7.0' +implementation 'com.google.cloud:google-cloud-logging:3.7.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-logging" % "3.7.0" +libraryDependencies += "com.google.cloud" % "google-cloud-logging" % "3.7.1" ``` ## Authentication From 0af5a22589c4ad5db5d98fdbdfaf3cb03762ca7c Mon Sep 17 00:00:00 2001 From: Mridula Peddada Date: Mon, 7 Mar 2022 09:26:56 -0500 Subject: [PATCH 11/12] improve test setup --- .../logging/ITNativeImageLoggingSample.java | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java b/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java index 1708174bd..dd6a5feab 100644 --- a/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java +++ b/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java @@ -18,28 +18,19 @@ import static com.google.common.truth.Truth.assertThat; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import org.junit.Before; +import com.google.cloud.testing.junit4.StdOutCaptureRule; +import org.junit.Rule; import org.junit.Test; public class ITNativeImageLoggingSample { - private ByteArrayOutputStream bout; - private PrintStream out; - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - System.setOut(out); - } + @Rule + public StdOutCaptureRule stdOut = new StdOutCaptureRule(); @Test public void testLogging() throws Exception { - bout.reset(); - NativeImageLoggingSample.main(new String[] {}); - String output = bout.toString(); - assertThat(output).contains("Logged: This is a log produced by Native Image."); + NativeImageLoggingSample.main(new String[]{}); + assertThat(stdOut.getCapturedOutputAsUtf8String()).contains( + "Logged: This is a log produced by Native Image."); } } From 9b93d5a025fc2d7d732d32dedb42b1c6336bf24c Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 7 Mar 2022 14:32:11 +0000 Subject: [PATCH 12/12] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../com/example/logging/ITNativeImageLoggingSample.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java b/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java index dd6a5feab..6a4ba67ca 100644 --- a/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java +++ b/samples/native-image-sample/src/test/java/com/example/logging/ITNativeImageLoggingSample.java @@ -24,13 +24,12 @@ public class ITNativeImageLoggingSample { - @Rule - public StdOutCaptureRule stdOut = new StdOutCaptureRule(); + @Rule public StdOutCaptureRule stdOut = new StdOutCaptureRule(); @Test public void testLogging() throws Exception { - NativeImageLoggingSample.main(new String[]{}); - assertThat(stdOut.getCapturedOutputAsUtf8String()).contains( - "Logged: This is a log produced by Native Image."); + NativeImageLoggingSample.main(new String[] {}); + assertThat(stdOut.getCapturedOutputAsUtf8String()) + .contains("Logged: This is a log produced by Native Image."); } }