diff --git a/logging/cloud-client/README.md b/logging/cloud-client/README.md
index f98475a9aff..2b0c8630204 100644
--- a/logging/cloud-client/README.md
+++ b/logging/cloud-client/README.md
@@ -3,27 +3,32 @@
[Stackdriver Logging][logging] allows you to store, search, analyze, monitor,
and alert on log data and events from Google Cloud Platform and Amazon Web
Services.
-These sample Java applications demonstrate how to access the Cloud Storage API using
+These sample Java applications demonstrate how to access the Stackdriver Logging API using
the [Google Cloud Client Library for Java][google-cloud-java].
[logging]: https://cloud.google.com/logging/
[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java
-## Quickstart
+## Setup
Install [Maven](http://maven.apache.org/).
Build your project with:
mvn clean package -DskipTests
-
-You can then run a given `ClassName` via:
-
- mvn exec:java -Dexec.mainClass=com.example.logging.ClassName \
- -DpropertyName=propertyValue \
- -Dexec.args="any arguments to the app"
+
+[Setup authentication](https://cloud.google.com/docs/authentication) using a service account.
### Writing a log entry (using the quickstart sample)
mvn exec:java -Dexec.mainClass=com.example.logging.QuickstartSample \
-Dexec.args="my-log"
+
+
+### List log entries
+
+ mvn exec:java -Dexec.mainClass=com.example.logging.ListLogs \
+ -Dexec.args="my-log"
+
+
+Logs can also viewed using the [Logs Viewer Console](https://pantheon.corp.google.com/logs/viewer).
diff --git a/logging/cloud-client/pom.xml b/logging/cloud-client/pom.xml
index 853cebb1e1b..c99554d74a6 100644
--- a/logging/cloud-client/pom.xml
+++ b/logging/cloud-client/pom.xml
@@ -16,15 +16,15 @@
4.0.0
com.example.logging
- logging-google-cloud-samples
+ logging-google-cloud-samples-api
jar
- doc-samples
- com.google.cloud
+ com.google.cloud.logging.samples
+ cloud-logging-samples
1.0.0
- ../..
+ ..
@@ -37,7 +37,7 @@
com.google.cloud
google-cloud-logging
- 1.3.1
+ 1.4.0
diff --git a/logging/cloud-client/src/main/java/com/example/logging/QuickstartSample.java b/logging/cloud-client/src/main/java/com/example/logging/QuickstartSample.java
index 58d5e92a97b..444642e0f9e 100644
--- a/logging/cloud-client/src/main/java/com/example/logging/QuickstartSample.java
+++ b/logging/cloud-client/src/main/java/com/example/logging/QuickstartSample.java
@@ -1,5 +1,5 @@
/*
- Copyright 2016, Google, Inc.
+ Copyright 2016 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -17,19 +17,25 @@
package com.example.logging;
// [START logging_quickstart]
-// Imports the Google Cloud client library
-
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;
+/**
+ * This sample demonstrates writing logs using the Stackdriver Logging API.
+ * The library also offers a java.util.logging Handler `com.google.cloud.logging.LoggingHandler`
+ * Logback integration is also available : https://goo.gl/DNMoRh
+ * Using the java.util.logging handler / Logback appender should be preferred to using the API directly.
+ */
public class QuickstartSample {
+ /** Expects a new or existing Stackdriver log name as the first argument.*/
public static void main(String... args) throws Exception {
+
// Instantiates a client
Logging logging = LoggingOptions.getDefaultInstance().getService();
@@ -40,11 +46,12 @@ public static void main(String... args) throws Exception {
String text = "Hello, world!";
LogEntry entry = LogEntry.newBuilder(StringPayload.of(text))
+ .setSeverity(Severity.ERROR)
.setLogName(logName)
.setResource(MonitoredResource.newBuilder("global").build())
.build();
- // Writes the log entry
+ // Writes the log entry asynchronously
logging.write(Collections.singleton(entry));
System.out.printf("Logged: %s%n", text);
diff --git a/logging/cloud-client/src/test/java/com/example/logging/QuickstartSampleIT.java b/logging/cloud-client/src/test/java/com/example/logging/LoggingIT.java
similarity index 55%
rename from logging/cloud-client/src/test/java/com/example/logging/QuickstartSampleIT.java
rename to logging/cloud-client/src/test/java/com/example/logging/LoggingIT.java
index 66aa5685a65..1abbca0906b 100644
--- a/logging/cloud-client/src/test/java/com/example/logging/QuickstartSampleIT.java
+++ b/logging/cloud-client/src/test/java/com/example/logging/LoggingIT.java
@@ -1,5 +1,5 @@
/*
- Copyright 2016, Google, Inc.
+ Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -18,37 +18,37 @@
import static com.google.common.truth.Truth.assertThat;
+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 java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.Collections;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-
/**
* Tests for quickstart sample.
*/
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
-public class QuickstartSampleIT {
+public class LoggingIT {
private ByteArrayOutputStream bout;
private PrintStream out;
+ private Logging logging = LoggingOptions.getDefaultInstance().getService();
- private static final void deleteMyLog() {
- Logging logging = LoggingOptions.getDefaultInstance().getService();
-
- logging.deleteLog("my-log");
+ private void deleteLog(String logName) {
+ logging.deleteLog(logName);
}
@Before
public void setUp() {
- deleteMyLog();
-
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
System.setOut(out);
@@ -57,13 +57,36 @@ public void setUp() {
@After
public void tearDown() {
System.setOut(null);
- deleteMyLog();
}
@Test
public void testQuickstart() throws Exception {
- QuickstartSample.main("my-log");
+ String logName = "my-log";
+ deleteLog(logName);
+ QuickstartSample.main(logName);
String got = bout.toString();
assertThat(got).contains("Logged: Hello, world!");
+ deleteLog(logName);
+ }
+
+ @Test(timeout = 10000)
+ public void testWriteAndListLogs() throws Exception {
+ String logName = "test-log";
+ deleteLog(logName);
+ // write a log entry
+ LogEntry entry = LogEntry.newBuilder(StringPayload.of("Hello world again"))
+ .setLogName(logName)
+ .setResource(MonitoredResource.newBuilder("global").build())
+ .build();
+ logging.write(Collections.singleton(entry));
+ // flush out log immediately
+ logging.flush();
+ bout.reset();
+ while (bout.toString().isEmpty()) {
+ ListLogs.main(logName);
+ Thread.sleep(1000);
+ }
+ assertThat(bout.toString().contains("Hello world again")).isTrue();
+ deleteLog(logName);
}
}
diff --git a/logging/jul/README.md b/logging/jul/README.md
new file mode 100644
index 00000000000..90f91b14c2d
--- /dev/null
+++ b/logging/jul/README.md
@@ -0,0 +1,37 @@
+# Getting Started with Stackdriver Logging using `java.util.logging`
+
+[Stackdriver Logging][logging] allows you to store, search, analyze, monitor,
+and alert on log data and events from Google Cloud Platform and Amazon Web
+Services.
+These sample Java applications demonstrate how to write logs to Stackdriver using
+the default Java Logging API (`java.util.logging`) handler for
+[Google Cloud Client Library for Java][google-cloud-java].
+
+[logging]: https://cloud.google.com/logging/
+[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java
+
+## Setup
+
+Install [Maven](http://maven.apache.org/).
+
+Build your project with:
+
+ mvn clean package -DskipTests
+
+[Setup authentication](https://cloud.google.com/docs/authentication) using a service account.
+
+## Configuration
+
+Update [logging.properties](src/main/resources/logging.properties) to configure the handler.
+
+## Enhancers
+
+[ExampleEnhancer.java](src/main/java/com/example/logging/jul/enhancers/ExampleEnhancer.java)
+provides an example of enhancing log entries with additional labels.
+
+
+## Writing log entries
+ mvn exec:java -Dexec.mainClass=com.example.logging.jul.Quickstart \
+ -Dexec.args="-Djava.util.logging.file=src/main/resources/logging.properties"
+
+Logs can be viewed using the [Logs Viewer Console](https://pantheon.corp.google.com/logs/viewer).
diff --git a/logging/jul/pom.xml b/logging/jul/pom.xml
new file mode 100644
index 00000000000..8ac8c19d7f7
--- /dev/null
+++ b/logging/jul/pom.xml
@@ -0,0 +1,57 @@
+
+
+ 4.0.0
+ com.example.logging
+ logging-google-cloud-samples-jul
+ jar
+
+
+
+ com.google.cloud.logging.samples
+ cloud-logging-samples
+ 1.0.0
+ ..
+
+
+
+ 1.8
+ 1.8
+ UTF-8
+
+
+
+
+ com.google.cloud
+ google-cloud-logging
+ 1.4.0
+
+
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+ com.google.truth
+ truth
+ 0.34
+ test
+
+
+
diff --git a/logging/jul/src/main/java/com/example/logging/jul/Quickstart.java b/logging/jul/src/main/java/com/example/logging/jul/Quickstart.java
new file mode 100644
index 00000000000..f75801f7f9a
--- /dev/null
+++ b/logging/jul/src/main/java/com/example/logging/jul/Quickstart.java
@@ -0,0 +1,31 @@
+/*
+ Copyright 2017 Google Inc.
+
+ 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
+
+ http://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.jul;
+
+// [START jul_quickstart]
+
+import java.util.logging.Logger;
+
+public class Quickstart {
+ private static final Logger logger = Logger.getLogger(Quickstart.class.getName());
+
+ public static void main(String[] args) {
+ logger.info("Logging INFO with java.util.logging");
+ logger.severe("Logging ERROR with java.util.logging");
+ }
+}
+// [END jul_quickstart]
\ No newline at end of file
diff --git a/logging/jul/src/main/java/com/example/logging/jul/enhancers/ExampleEnhancer.java b/logging/jul/src/main/java/com/example/logging/jul/enhancers/ExampleEnhancer.java
new file mode 100644
index 00000000000..20be8259139
--- /dev/null
+++ b/logging/jul/src/main/java/com/example/logging/jul/enhancers/ExampleEnhancer.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.jul.enhancers;
+
+import com.google.cloud.logging.LogEntry;
+import com.google.cloud.logging.LoggingEnhancer;
+
+// Add / update additional fields to the log entry
+public class ExampleEnhancer implements LoggingEnhancer {
+
+ @Override
+ public void enhanceLogEntry(LogEntry.Builder logEntry) {
+ // add additional labels
+ logEntry.addLabel("test-label-1", "test-value-1");
+ }
+}
diff --git a/logging/jul/src/main/resources/logging.properties b/logging/jul/src/main/resources/logging.properties
new file mode 100644
index 00000000000..04d1832bf21
--- /dev/null
+++ b/logging/jul/src/main/resources/logging.properties
@@ -0,0 +1,29 @@
+# A default java.util.logging configuration.
+#
+# [START jul_config]
+# To use this configuration, add to system properties : -Djava.util.logging.config.file="/path/to/file"
+#
+.level = INFO
+
+# it is recommended that io.grpc and sun.net logging level is kept at INFO level,
+# as both these packages are used by Stackdriver internals and can result in verbose / initialization problems.
+io.grpc.netty.level=INFO
+sun.net.level=INFO
+
+com.example.logging.jul.Quickstart.handlers=com.google.cloud.logging.LoggingHandler
+# default : java.log
+com.google.cloud.logging.LoggingHandler.log=custom_log
+
+# default : INFO
+com.google.cloud.logging.LoggingHandler.level=FINE
+
+# default : ERROR
+com.google.cloud.logging.LoggingHandler.flushLevel=ERROR
+
+# custom formatter
+com.google.cloud.logging.LoggingHandler.formatter=java.util.logging.SimpleFormatter
+java.util.logging.SimpleFormatter.format=%3$s: %5$s%6$s
+
+#optional enhancers (to add additional fields, labels)
+com.google.cloud.logging.LoggingHandler.enhancers=com.example.logging.jul.enhancers.ExampleEnhancer
+# [END jul_config]
\ No newline at end of file
diff --git a/logging/logback/README.md b/logging/logback/README.md
new file mode 100644
index 00000000000..b12c0c9890b
--- /dev/null
+++ b/logging/logback/README.md
@@ -0,0 +1,38 @@
+# Getting Started with Stackdriver Logging using Logback
+
+[Stackdriver Logging][logging] allows you to store, search, analyze, monitor,
+and alert on log data and events from Google Cloud Platform and Amazon Web
+Services.
+
+These sample Java applications demonstrate how to write logs to Stackdriver using
+[Logback](https://logback.qos.ch/) appender for [Google Cloud Client Library for Java][google-cloud-java].
+
+[logging]: https://cloud.google.com/logging/
+[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java
+
+## Setup
+
+Install [Maven](http://maven.apache.org/).
+
+Build your project with:
+
+ mvn clean package -DskipTests
+
+[Setup authentication](https://cloud.google.com/docs/authentication) using a service account.
+
+## Configuration
+
+Update [logback.xml](src/main/resources/logback.xml) to configure the appender.
+
+More information on Logback configuration can be found
+[here](https://logback.qos.ch/manual/configuration.html).
+
+## Enhancers
+[ExampleEnhancer.java](src/main/java/com/example/logging/logback/enhancers/ExampleEnhancer.java)
+provides an example of enhancing log entries with additional labels.
+
+
+## Writing log entries
+ mvn exec:java -Dexec.mainClass=com.example.logging.logback.Quickstart
+
+Logs can be viewed using the [Logs Viewer Console](https://pantheon.corp.google.com/logs/viewer).
diff --git a/logging/logback/pom.xml b/logging/logback/pom.xml
new file mode 100644
index 00000000000..8c69a0b9368
--- /dev/null
+++ b/logging/logback/pom.xml
@@ -0,0 +1,57 @@
+
+
+ 4.0.0
+ com.example.logging
+ logging-google-cloud-samples-logback
+ jar
+
+
+
+ com.google.cloud.logging.samples
+ cloud-logging-samples
+ 1.0.0
+ ..
+
+
+
+ 1.8
+ 1.8
+ UTF-8
+
+
+
+
+ com.google.cloud
+ google-cloud-logging-logback
+ 0.22.0-alpha
+
+
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+ com.google.truth
+ truth
+ 0.34
+ test
+
+
+
diff --git a/logging/logback/src/main/java/com/example/logging/logback/Quickstart.java b/logging/logback/src/main/java/com/example/logging/logback/Quickstart.java
new file mode 100644
index 00000000000..d646cadcad0
--- /dev/null
+++ b/logging/logback/src/main/java/com/example/logging/logback/Quickstart.java
@@ -0,0 +1,31 @@
+/*
+ Copyright 2017 Google Inc.
+
+ 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
+
+ http://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.logback;
+
+// [START logback_quickstart]
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Quickstart {
+ private static final Logger logger = LoggerFactory.getLogger(Quickstart.class);
+
+ public static void main(String[] args) {
+ logger.info("Logging INFO with Logback");
+ logger.error("Logging ERROR with Logback");
+ }
+}
+// [END logback_quickstart]
\ No newline at end of file
diff --git a/logging/logback/src/main/java/com/example/logging/logback/enhancers/ExampleEnhancer.java b/logging/logback/src/main/java/com/example/logging/logback/enhancers/ExampleEnhancer.java
new file mode 100644
index 00000000000..b99c82efe1f
--- /dev/null
+++ b/logging/logback/src/main/java/com/example/logging/logback/enhancers/ExampleEnhancer.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * 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
+ *
+ * http://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.logback.enhancers;
+// [START logging_enhancer]
+import com.google.cloud.logging.LogEntry;
+import com.google.cloud.logging.LoggingEnhancer;
+
+// Add / update additional fields to the log entry
+public class ExampleEnhancer implements LoggingEnhancer {
+
+ @Override
+ public void enhanceLogEntry(LogEntry.Builder logEntry) {
+ // add additional labels
+ logEntry.addLabel("test-label-1", "test-value-1");
+ }
+}
+// [END logging_enhancer]
\ No newline at end of file
diff --git a/logging/logback/src/main/resources/logback.xml b/logging/logback/src/main/resources/logback.xml
new file mode 100644
index 00000000000..3cd36e776ca
--- /dev/null
+++ b/logging/logback/src/main/resources/logback.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+ INFO
+
+ application.log
+ com.example.logging.logback.enhancers.ExampleEnhancer
+ WARN
+
+
+
+
+
+
+
diff --git a/logging/pom.xml b/logging/pom.xml
index b2cc05516cf..1d678a90d2e 100644
--- a/logging/pom.xml
+++ b/logging/pom.xml
@@ -18,7 +18,7 @@ limitations under the License.
4.0.0
com.google.cloud.logging.samples
cloud-logging-samples
- jar
+ pom
doc-samples
@@ -32,35 +32,16 @@ limitations under the License.
1.8
+
+ logback
+ jul
+ cloud-client
+
+
-
- com.google.apis
- google-api-services-logging
- v1beta3-rev10-1.21.0
-
-
- com.google.oauth-client
- google-oauth-client
- ${project.oauth.version}
-
-
- com.google.http-client
- google-http-client-jackson2
- ${project.http.version}
-
-
- com.google.oauth-client
- google-oauth-client-jetty
- ${project.oauth.version}
-
junit
junit
-
- com.jcabi
- jcabi-matchers
-
-
diff --git a/logging/src/main/java/ListLogs.java b/logging/src/main/java/ListLogs.java
deleted file mode 100644
index db4252bf4e6..00000000000
--- a/logging/src/main/java/ListLogs.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/**
- * Copyright (c) 2015 Google Inc.
- *
- * 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
- *
- * http://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.
- */
-// [START imports]
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.http.HttpTransport;
-import com.google.api.client.http.javanet.NetHttpTransport;
-import com.google.api.client.json.JsonFactory;
-import com.google.api.client.json.jackson2.JacksonFactory;
-import com.google.api.client.util.Strings;
-import com.google.api.services.logging.Logging;
-import com.google.api.services.logging.LoggingScopes;
-import com.google.api.services.logging.model.ListLogsResponse;
-import com.google.api.services.logging.model.Log;
-
-import java.io.IOException;
-import java.net.URLDecoder;
-import java.util.Collections;
-import java.util.List;
-// [END imports]
-
-/**
- * Cloud Logging Java API sample that lists the logs available to a project.
- * Uses the v1beta3 Cloud Logging API, version 1.20.0 or later.
- * See https://cloud.google.com/logging/docs/api/libraries/.
- */
-public class ListLogs {
-
- private static final List LOGGING_SCOPES = Collections.singletonList(
- LoggingScopes.LOGGING_READ);
-
- private static final String APPLICATION_NAME = "ListLogs sample";
-
- /**
- * Returns an authorized Cloud Logging API service client that is usable
- * on Google App Engine, Google Compute Engine, workstations with the Google Cloud SDK,
- * and other computers if you install service account private credentials.
- * See https://cloud.google.com/logging/docs/api/tasks.
- */
- // [START auth]
- public static Logging getLoggingService() throws IOException {
- HttpTransport transport = new NetHttpTransport();
- JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
- if (credential.createScopedRequired()) {
- credential = credential.createScoped(LOGGING_SCOPES);
- }
- Logging service = new Logging.Builder(transport, jsonFactory, credential)
- .setApplicationName(APPLICATION_NAME).build();
- return service;
- }
- // [END auth]
-
- /**
- * Lists the names of the logs visible to a project, which may require fetching multiple
- * pages of results from the Cloud Logging API. This method converts log resource names
- * ("/projects/PROJECTID/logs/SERVICENAME%2FLOGNAME") to simple log names ("SERVICENAME/LOGNAME").
- *
- * @param service The logging service client returned by getLoggingService.
- * @param projectId The project whose logs are to be listed.
- * @throws IOException If the Cloud Logging API fails because, for example, the project ID
- * doesn't exist or authorization fails.
- * See https://cloud.google.com//logging/docs/api/tasks/#java_sample_code.
- */
- // [START listlogs]
- private static void listLogs(Logging service, String projectId) throws IOException {
- final int pageSize = 3;
- final int resourcePrefixLength = ("/projects/" + projectId + "/logs/").length();
- String nextPageToken = "";
-
- do {
- ListLogsResponse response = service.projects().logs().list(projectId)
- .setPageToken(nextPageToken).setPageSize(pageSize).execute();
- if (response.isEmpty()) {
- break;
- }
- for (Log log: response.getLogs()) {
- System.out.println(URLDecoder.decode(
- log.getName().substring(resourcePrefixLength), "utf-8"));
- }
- nextPageToken = response.getNextPageToken();
- } while (!Strings.isNullOrEmpty(nextPageToken));
- System.out.println("Done.");
- }
- // [END listlogs]
-
- /**
- * Demonstrates the Cloud Logging API by listing the logs in a project.
- * @param args The project ID.
- * @throws IOException if a Cloud Logging API call fails because, say, the project ID is wrong
- * or authorization fails.
- */
- public static void main(String[] args) throws IOException {
- if (args.length != 1) {
- System.err.println(String.format("Usage: %s ",
- ListLogs.class.getSimpleName()));
- return;
- }
-
- String projectId = args[0];
- Logging service = getLoggingService();
- listLogs(service, projectId);
- }
-}
-// [END all]
diff --git a/logging/src/test/java/ListLogsTest.java b/logging/src/test/java/ListLogsTest.java
deleted file mode 100644
index 45efec69444..00000000000
--- a/logging/src/test/java/ListLogsTest.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * Copyright 2015 Google Inc.
- *
- * 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
- *
- * http://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.
- */
-import static com.jcabi.matchers.RegexMatchers.containsPattern;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-
-/**
- * Tests the Cloud Logging sample.
- */
-public class ListLogsTest {
- private final ByteArrayOutputStream stdout = new ByteArrayOutputStream();
- private final ByteArrayOutputStream stderr = new ByteArrayOutputStream();
- private static final PrintStream REAL_OUT = System.out;
- private static final PrintStream REAL_ERR = System.err;
- private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
-
- @Before
- public void setUp() {
- System.setOut(new PrintStream(stdout));
- System.setErr(new PrintStream(stderr));
- }
-
- @After
- public void tearDown() {
- System.setOut(ListLogsTest.REAL_OUT);
- System.setErr(ListLogsTest.REAL_ERR);
- }
-
- @Test
- public void testUsage() throws Exception {
- ListLogs.main(new String[] {});
- assertEquals("Usage: ListLogs \n", stderr.toString());
- }
-
- @Test
- public void testListLogs() throws Exception {
- ListLogs.main(new String[] {PROJECT_ID});
- String out = stdout.toString();
- // Don't know what logs the test project will have.
- assertThat(out, containsPattern("Done\\."));
- }
-}
diff --git a/pom.xml b/pom.xml
index 8cec39abbd4..fe7f9e86aa0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,7 +16,6 @@
4.0.0
1.0.0
-
com.google.cloud
doc-samples
pom