Skip to content

Commit 790fb1a

Browse files
fix: modify list log entries example documentation (#740)
modify list log entries example doc remove reference to unmanaged code in google-cloud-java. * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 8603e8e commit 790fb1a

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

.readme-partials.yaml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ custom_content: |
9494
imports at the top of your file:
9595
9696
```java
97-
import com.google.cloud.Page;
97+
import com.google.api.gax.paging.Page;
9898
import com.google.cloud.logging.LogEntry;
9999
import com.google.cloud.logging.Logging.EntryListOption;
100100
```
@@ -104,12 +104,13 @@ custom_content: |
104104
``` java
105105
Page<LogEntry> entries = logging.listLogEntries(
106106
EntryListOption.filter("logName=projects/" + options.getProjectId() + "/logs/test-log"));
107-
Iterator<LogEntry> entryIterator = entries.iterateAll().iterator();
108-
while (entryIterator.hasNext()) {
109-
System.out.println(entryIterator.next());
107+
while (entries != null) {
108+
for (LogEntry logEntry : entries.iterateAll()) {
109+
System.out.println(logEntry);
110+
}
111+
entries = entries.getNextPage();
110112
}
111113
```
112-
113114
#### Add a Cloud Logging handler to a logger
114115
115116
You can also register a `LoggingHandler` to a `java.util.logging.Logger` that publishes log entries
@@ -133,13 +134,3 @@ custom_content: |
133134
```
134135
com.google.cloud.examples.logging.snippets.AddLoggingHandler.handlers=com.google.cloud.logging.LoggingHandler
135136
```
136-
137-
#### Complete source code
138-
139-
In
140-
[CreateAndListMetrics.java](https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListMetrics.java),
141-
[WriteAndListLogEntries.java](https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/WriteAndListLogEntries.java)
142-
and
143-
[AddLoggingHandler.java](https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/AddLoggingHandler.java)
144-
we put together all the code shown above into three programs. The programs assume that you are
145-
running on Compute Engine or from your own desktop.

README.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ With Logging you can also list log entries that have been previously written. Ad
194194
imports at the top of your file:
195195

196196
```java
197-
import com.google.cloud.Page;
197+
import com.google.api.gax.paging.Page;
198198
import com.google.cloud.logging.LogEntry;
199199
import com.google.cloud.logging.Logging.EntryListOption;
200200
```
@@ -204,12 +204,13 @@ Then, to list the log entries, use the following code:
204204
``` java
205205
Page<LogEntry> entries = logging.listLogEntries(
206206
EntryListOption.filter("logName=projects/" + options.getProjectId() + "/logs/test-log"));
207-
Iterator<LogEntry> entryIterator = entries.iterateAll().iterator();
208-
while (entryIterator.hasNext()) {
209-
System.out.println(entryIterator.next());
207+
while (entries != null) {
208+
for (LogEntry logEntry : entries.iterateAll()) {
209+
System.out.println(logEntry);
210+
}
211+
entries = entries.getNextPage();
210212
}
211213
```
212-
213214
#### Add a Cloud Logging handler to a logger
214215

215216
You can also register a `LoggingHandler` to a `java.util.logging.Logger` that publishes log entries
@@ -234,15 +235,6 @@ file. Adding, for instance, the following line:
234235
com.google.cloud.examples.logging.snippets.AddLoggingHandler.handlers=com.google.cloud.logging.LoggingHandler
235236
```
236237

237-
#### Complete source code
238-
239-
In
240-
[CreateAndListMetrics.java](https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/CreateAndListMetrics.java),
241-
[WriteAndListLogEntries.java](https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/WriteAndListLogEntries.java)
242-
and
243-
[AddLoggingHandler.java](https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/logging/snippets/AddLoggingHandler.java)
244-
we put together all the code shown above into three programs. The programs assume that you are
245-
running on Compute Engine or from your own desktop.
246238

247239

248240

0 commit comments

Comments
 (0)