@@ -194,7 +194,7 @@ With Logging you can also list log entries that have been previously written. Ad
194
194
imports at the top of your file:
195
195
196
196
``` java
197
- import com.google.cloud .Page ;
197
+ import com.google.api.gax.paging .Page ;
198
198
import com.google.cloud.logging.LogEntry ;
199
199
import com.google.cloud.logging.Logging.EntryListOption ;
200
200
```
@@ -204,12 +204,13 @@ Then, to list the log entries, use the following code:
204
204
``` java
205
205
Page<LogEntry > entries = logging. listLogEntries(
206
206
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();
210
212
}
211
213
```
212
-
213
214
#### Add a Cloud Logging handler to a logger
214
215
215
216
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:
234
235
com.google.cloud.examples.logging.snippets.AddLoggingHandler.handlers=com.google.cloud.logging.LoggingHandler
235
236
```
236
237
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.
246
238
247
239
248
240
0 commit comments