Using GCP's Java SDK, I'd like to read only logs that are not configured to be exported to any sink.
When I call com.google.cloud.logging.Logging.listLogEntries()
I get all of the logs, including logs are exported to sinks I have configured.
Any way to collect only log entries that are not configured to be exported to any sink?
You need to use EntryListOption
to get filtered log entries as explained on this page.
Page<LogEntry> entries = logging.listLogEntries(
EntryListOption.filter("logName=projects/" + options.getProjectId() + "/logs/test-log"));
Iterator<LogEntry> entryIterator = entries.iterateAll().iterator();
while (entryIterator.hasNext()) {
System.out.println(entryIterator.next());
}
Any way to collect only log entries that are not configured to be exported to any sink?
In order to achieve this,
you need to get all sinks using REST api or equivalent java client
iterate over sinks to get each filter query
build a dynamic filter to use with the above EntryListOption