Interface Logging
- All Superinterfaces:
AutoCloseable
,com.google.cloud.Service<LoggingOptions>
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic final class
Class for specifying options for listing log entries.static final class
Class for specifying options for listing sinks, monitored resources and monitored resource descriptors.static enum
Fields according to which log entries can be sorted.static enum
Sorting orders available when listing log entries.static final class
Class for specifying options for tailing log entries.static final class
Class for specifying options for writing log entries. -
Method Summary
Modifier and TypeMethodDescriptionCreates a new exclusion in a specified parent resource.create
(MetricInfo metric) Creates a new metric.Creates a new sink.com.google.api.core.ApiFuture<Exclusion>
createAsync
(Exclusion exclusion) Sends a request to create the exclusion.com.google.api.core.ApiFuture<Metric>
createAsync
(MetricInfo metric) Sends a request for creating a metric.com.google.api.core.ApiFuture<Sink>
createAsync
(SinkInfo sink) Sends a request for creating a sink.boolean
deleteExclusion
(String exclusion) Deletes the requested exclusion.com.google.api.core.ApiFuture<Boolean>
deleteExclusionAsync
(String exclusion) Sends a request to delete an exclusion.boolean
Deletes a log and all its log entries.default boolean
deleteLog
(String log, LogDestinationName destination) Deletes a log and all its log entries for given log destination (see 'logName' parameter in https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry).com.google.api.core.ApiFuture<Boolean>
deleteLogAsync
(String log) Sends a request for deleting a log and all its log entries.default com.google.api.core.ApiFuture<Boolean>
deleteLogAsync
(String log, LogDestinationName destination) Sends a request for deleting a log and all its log entries for given log destination (see 'logName' parameter in https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry).boolean
deleteMetric
(String metric) Deletes the requested metric.com.google.api.core.ApiFuture<Boolean>
deleteMetricAsync
(String metric) Sends a request for deleting a metric.boolean
deleteSink
(String sink) Deletes the requested sink.com.google.api.core.ApiFuture<Boolean>
deleteSinkAsync
(String sink) Sends a request for deleting a sink.void
flush()
Flushes any pending asynchronous logging writes.getExclusion
(String exclusion) Gets the description of an exclusion ornull
if not found.com.google.api.core.ApiFuture<Exclusion>
getExclusionAsync
(String exclusion) Sends a request to get the description of an exclusion .Returns the requested metric ornull
if not found.com.google.api.core.ApiFuture<Metric>
getMetricAsync
(String metric) Sends a request for getting a metric.Returns the requested sink ornull
if not found.com.google.api.core.ApiFuture<Sink>
getSinkAsync
(String sink) Sends a request for getting a sink.Retrieves current set synchronicitySynchronicity
of logging writes.com.google.api.gax.paging.Page<Exclusion>
listExclusions
(Logging.ListOption... options) Lists the exclusion.com.google.api.core.ApiFuture<com.google.api.gax.paging.AsyncPage<Exclusion>>
listExclusionsAsync
(Logging.ListOption... options) Sends a request for listing exclusions.com.google.api.gax.paging.Page<LogEntry>
listLogEntries
(Logging.EntryListOption... options) Lists log entries.com.google.api.core.ApiFuture<com.google.api.gax.paging.AsyncPage<LogEntry>>
listLogEntriesAsync
(Logging.EntryListOption... options) Sends a request for listing log entries.default com.google.api.gax.paging.Page<String>
listLogs
(Logging.ListOption... options) Lists the log names.default com.google.api.core.ApiFuture<com.google.api.gax.paging.AsyncPage<String>>
listLogsAsync
(Logging.ListOption... options) Sends a request for listing log names.com.google.api.gax.paging.Page<Metric>
listMetrics
(Logging.ListOption... options) Lists the metrics.com.google.api.core.ApiFuture<com.google.api.gax.paging.AsyncPage<Metric>>
listMetricsAsync
(Logging.ListOption... options) Sends a request for listing metrics.com.google.api.gax.paging.Page<com.google.cloud.MonitoredResourceDescriptor>
listMonitoredResourceDescriptors
(Logging.ListOption... options) Lists the monitored resource descriptors used by Cloud Logging.com.google.api.core.ApiFuture<com.google.api.gax.paging.AsyncPage<com.google.cloud.MonitoredResourceDescriptor>>
Sends a request for listing monitored resource descriptors used by Cloud Logging.com.google.api.gax.paging.Page<Sink>
listSinks
(Logging.ListOption... options) Lists the sinks.com.google.api.core.ApiFuture<com.google.api.gax.paging.AsyncPage<Sink>>
listSinksAsync
(Logging.ListOption... options) Sends a request for listing sinks.populateMetadata
(Iterable<LogEntry> logEntries, com.google.cloud.MonitoredResource customResource, String... exclusionClassPaths) Populates metadata fields of the immutable collection ofLogEntry
items.void
setFlushSeverity
(Severity flushSeverity) Sets flush severity for asynchronous logging writes.void
setWriteSynchronicity
(Synchronicity synchronicity) Sets synchronicitySynchronicity
of logging writes, defaults to asynchronous.tailLogEntries
(Logging.TailOption... options) Sends a request to stream fresh log entries.Updates one or more properties of an existing exclusion.update
(MetricInfo metric) Updates a metric or creates one if it does not exist.Updates a sink or creates one if it does not exist.com.google.api.core.ApiFuture<Exclusion>
updateAsync
(Exclusion exclusion) Sends a request to change one or more properties of an existing exclusion.com.google.api.core.ApiFuture<Metric>
updateAsync
(MetricInfo metric) Sends a request for updating a metric (or creating it, if it does not exist).com.google.api.core.ApiFuture<Sink>
updateAsync
(SinkInfo sink) Sends a request for updating a sink (or creating it, if it does not exist).void
write
(Iterable<LogEntry> logEntries, Logging.WriteOption... options) Sends a request to log entries to Cloud Logging.Methods inherited from interface java.lang.AutoCloseable
close
Methods inherited from interface com.google.cloud.Service
getOptions
-
Method Details
-
setWriteSynchronicity
Sets synchronicitySynchronicity
of logging writes, defaults to asynchronous. -
getWriteSynchronicity
Synchronicity getWriteSynchronicity()Retrieves current set synchronicitySynchronicity
of logging writes. -
setFlushSeverity
Sets flush severity for asynchronous logging writes. It is disabled by default, enabled when this method is called with anySeverity
value other thanSeverity.NONE
. Logs will be immediately written out for entries at or higher than flush severity.Enabling this can cause the leaking and hanging threads, see BUG(2796) BUG(3880). However you can explicitly call
flush()
.TODO: Enable this by default once functionality to trigger rpc is available in generated code.
-
getFlushSeverity
Severity getFlushSeverity() -
create
Creates a new sink.Example of creating a sink to export logs to a BigQuery dataset (in the
ServiceOptions.getProjectId()
project).{ @code String sinkName = "my_sink_name"; String datasetName = "my_dataset"; SinkInfo sinkInfo = SinkInfo.of(sinkName, DatasetDestination.of(datasetName)); Sink sink = logging.create(sinkInfo); }
- Returns:
- the created sink
- Throws:
LoggingException
- upon failure
-
create
Creates a new metric.Example of creating a metric for logs with severity higher or equal to ERROR.
{ @code String metricName = "my_metric_name"; MetricInfo metricInfo = MetricInfo.of(metricName, "severity>=ERROR"); Metric metric = logging.create(metricInfo); }
- Returns:
- the created metric
- Throws:
LoggingException
- upon failure
-
create
Creates a new exclusion in a specified parent resource. Only log entries belonging to that resource can be excluded. You can have up to 10 exclusions in a resource.Example of creating the exclusion:
{ @code String exclusionName = "my_exclusion_name"; Exclusion exclusion = Exclusion.of(exclusionName, "resource.type=gcs_bucket severity<ERROR sample(insertId, 0.99)"); Exclusion exclusion = logging.create(exclusion); }
- Returns:
- the created exclusion
- Throws:
LoggingException
- upon failure
-
createAsync
Sends a request for creating a sink. This method returns aApiFuture
object to consume the result.Future.get()
returns the created sink.Example of asynchronously creating a sink to export logs to a BigQuery dataset (in the
ServiceOptions.getProjectId()
project).String sinkName = "my_sink_name"; String datasetName = "my_dataset"; SinkInfo sinkInfo = SinkInfo.of(sinkName, DatasetDestination.of(datasetName)); ApiFuture<Sink> future = logging.createAsync(sinkInfo); // ... Sink sink = future.get();
-
createAsync
Sends a request for creating a metric. This method returns aApiFuture
object to consume the result.Future.get()
returns the created metric.Example of asynchronously creating a metric for logs with severity higher or equal to ERROR.
String metricName = "my_metric_name"; MetricInfo metricInfo = MetricInfo.of(metricName, "severity>=ERROR"); ApiFuture<Metric> future = logging.createAsync(metricInfo); // ... Metric metric = future.get();
-
createAsync
Sends a request to create the exclusion. This method returns anApiFuture
object to consume the result.Future.get()
returns the created exclusion.Example of asynchronously creating the exclusion:
String exclusionName = "my_exclusion_name"; Exclusion exclusion = Exclusion.of(exclusionName, "resource.type=gcs_bucket severity<ERROR sample(insertId, 0.99)"); ApiFuture<Exclusion> future = logging.createAsync(exclusion); // ... Exclusion exclusion = future.get();
-
update
Updates a sink or creates one if it does not exist.Example of updating a sink.
String sinkName = "my_sink_name"; String datasetName = "my_dataset"; SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName)) .setVersionFormat(SinkInfo.VersionFormat.V2).setFilter("severity>=ERROR").build(); Sink sink = logging.update(sinkInfo);
- Returns:
- the created sink
- Throws:
LoggingException
- upon failure
-
update
Updates a metric or creates one if it does not exist.Example of updating a metric.
String metricName = "my_metric_name"; MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR").setDescription("new description") .build(); Metric metric = logging.update(metricInfo);
- Returns:
- the created metric
- Throws:
LoggingException
- upon failure
-
update
Updates one or more properties of an existing exclusion.Example of updating the exclusion:
String exclusionName = "my_exclusion_name"; Exclusion exclusion = Exclusion .newBuilder(exclusionName, "resource.type=gcs_bucket severity<ERROR sample(insertId, 0.99)") .setDescription("new description").setIsDisabled(false).build(); Exclusion exclusion = logging.update(exclusion);
- Returns:
- the updated exclusion
- Throws:
LoggingException
- upon failure
-
updateAsync
Sends a request for updating a sink (or creating it, if it does not exist). This method returns aApiFuture
object to consume the result.Future.get()
returns the updated/created sink ornull
if not found.Example of asynchronously updating a sink.
String sinkName = "my_sink_name"; String datasetName = "my_dataset"; SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName)) .setVersionFormat(SinkInfo.VersionFormat.V2).setFilter("severity>=ERROR").build(); ApiFuture<Sink> future = logging.updateAsync(sinkInfo); // ... Sink sink = future.get();
-
updateAsync
Sends a request for updating a metric (or creating it, if it does not exist). This method returns aApiFuture
object to consume the result.Future.get()
returns the updated/created metric ornull
if not found.Example of asynchronously updating a metric.
String metricName = "my_metric_name"; MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR").setDescription("new description") .build(); ApiFuture<Metric> future = logging.updateAsync(metricInfo); // ... Metric metric = future.get();
-
updateAsync
Sends a request to change one or more properties of an existing exclusion. This method returns anApiFuture
object to consume the result.Future.get()
returns the updated exclusion ornull
if not found.Example of asynchronous exclusion update:
String exclusionName = "my_exclusion_name"; Exclusion exclusion = Exclusion .newBuilder(exclusionName, "resource.type=gcs_bucket severity<ERROR sample(insertId, 0.99)") .setDescription("new description").setIsDisabled(false).build(); ApiFuture<Exclusion> future = logging.updateAsync(exclusion); // ... Exclusion exclusion = future.get();
-
getSink
Returns the requested sink ornull
if not found.Example of getting a sink.
String sinkName = "my_sink_name"; Sink sink = logging.getSink(sinkName); if (sink == null) { // sink was not found }
- Throws:
LoggingException
- upon failure
-
getSinkAsync
Sends a request for getting a sink. This method returns aApiFuture
object to consume the result.Future.get()
returns the requested sink ornull
if not found.Example of asynchronously getting a sink.
String sinkName = "my_sink_name"; ApiFuture<Sink> future = logging.getSinkAsync(sinkName); // ... Sink sink = future.get(); if (sink == null) { // sink was not found }
- Throws:
LoggingException
- upon failure
-
listSinks
Lists the sinks. This method returns aPage
object that can be used to consume paginated results. UseLogging.ListOption
to specify the page size or the page token from which to start listing sinks.Example of listing sinks, specifying the page size.
Page<Sink> sinks = logging.listSinks(ListOption.pageSize(100)); Iterator<Sink> sinkIterator = sinks.iterateAll().iterator(); while (sinkIterator.hasNext()) { Sink sink = sinkIterator.next(); // do something with the sink }
- Throws:
LoggingException
- upon failure
-
listSinksAsync
com.google.api.core.ApiFuture<com.google.api.gax.paging.AsyncPage<Sink>> listSinksAsync(Logging.ListOption... options) Sends a request for listing sinks. This method returns aApiFuture
object to consume the result.Future.get()
returns anAsyncPage
object that can be used to asynchronously handle paginated results. UseLogging.ListOption
to specify the page size or the page token from which to start listing sinks.Example of asynchronously listing sinks, specifying the page size.
ApiFuture<AsyncPage<Sink>> future = logging.listSinksAsync(ListOption.pageSize(100)); // ... AsyncPage<Sink> sinks = future.get(); Iterator<Sink> sinkIterator = sinks.iterateAll().iterator(); while (sinkIterator.hasNext()) { Sink sink = sinkIterator.next(); // do something with the sink }
-
deleteSink
Deletes the requested sink.Example of deleting a sink.
String sinkName = "my_sink_name"; boolean deleted = logging.deleteSink(sinkName); if (deleted) { // the sink was deleted } else { // the sink was not found }
- Returns:
true
if the sink was deleted,false
if it was not found
-
deleteSinkAsync
Sends a request for deleting a sink. This method returns aApiFuture
object to consume the result.Future.get()
returnstrue
if the sink was deleted,false
if it was not found.Example of asynchronously deleting a sink.
String sinkName = "my_sink_name"; ApiFuture<Boolean> future = logging.deleteSinkAsync(sinkName); // ... boolean deleted = future.get(); if (deleted) { // the sink was deleted } else { // the sink was not found }
-
listLogs
Lists the log names. This method returns aPage
object that can be used to consume paginated results. UseLogging.ListOption
to specify the page size or the page token from which to start listing logs.Example of listing log names, specifying the page size.
Page<Log> logNames = logging.listLogs(ListOption.pageSize(100)); Iterator<Log> logIterator = logNames.iterateAll().iterator(); while (logIterator.hasNext()) { String logName = logIterator.next(); // do something with the log name }
- Throws:
LoggingException
- upon failure
-
listLogsAsync
default com.google.api.core.ApiFuture<com.google.api.gax.paging.AsyncPage<String>> listLogsAsync(Logging.ListOption... options) Sends a request for listing log names. This method returns aApiFuture
object to consume the result.Future.get()
returns anAsyncPage
object that can be used to asynchronously handle paginated results. UseLogging.ListOption
to specify the page size or the page token from which to start listing log names.Example of asynchronously listing log names, specifying the page size.
ApiFuture<AsyncPage<Log>> future = logging.listLogsAsync(ListOption.pageSize(100)); // ... AsyncPage<Sink> logNames = future.get(); Iterator<Sink> logIterator = logNames.iterateAll().iterator(); while (logIterator.hasNext()) { String logName = logIterator.next(); // do something with the log name }
-
deleteLog
Deletes a log and all its log entries. The log will reappear if new entries are written to it.Example of deleting a log.
String logName = "my_log_name"; boolean deleted = logging.deleteLog(logName); if (deleted) { // the log was deleted } else { // the log was not found }
- Returns:
true
if the log was deleted,false
if it was not found
-
deleteLog
Deletes a log and all its log entries for given log destination (see 'logName' parameter in https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry). The log will reappear if new entries are written to it.Example of deleting a log by folder destination.
String logName = "my_log_name"; String folder = "my_folder"; boolean deleted = logging.deleteLog(logName, LogDestinationName.folder(folder)); if (deleted) { // the log was deleted } else { // the log was not found }
- Returns:
true
if the log was deleted,false
if it was not found
-
deleteLogAsync
default com.google.api.core.ApiFuture<Boolean> deleteLogAsync(String log, LogDestinationName destination) Sends a request for deleting a log and all its log entries for given log destination (see 'logName' parameter in https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry). This method returns aApiFuture
object to consume the result.Future.get()
returnstrue
if the log was deleted,false
if it was not found.Example of asynchronously deleting a log by folder destination.
String logName = "my_log_name"; String folder = "my_folder"; ApiFuture<Boolean> future = logging.deleteLogAsync(logName, LogDestinationName.folder(folder)); // ... boolean deleted = future.get(); if (deleted) { // the log was deleted } else { // the log was not found }
-
deleteLogAsync
Sends a request for deleting a log and all its log entries. This method returns aApiFuture
object to consume the result.Future.get()
returnstrue
if the log was deleted,false
if it was not found.Example of asynchronously deleting a log.
String logName = "my_log_name"; ApiFuture<Boolean> future = logging.deleteLogAsync(logName); // ... boolean deleted = future.get(); if (deleted) { // the log was deleted } else { // the log was not found }
-
listMonitoredResourceDescriptors
com.google.api.gax.paging.Page<com.google.cloud.MonitoredResourceDescriptor> listMonitoredResourceDescriptors(Logging.ListOption... options) Lists the monitored resource descriptors used by Cloud Logging. This method returns aPage
object that can be used to consume paginated results. UseLogging.ListOption
to specify the page size or the page token from which to start listing resource descriptors.Example of listing monitored resource descriptors, specifying the page size.
Page<MonitoredResourceDescriptor> descriptors = logging .listMonitoredResourceDescriptors(ListOption.pageSize(100)); Iterator<MonitoredResourceDescriptor> descriptorIterator = descriptors.iterateAll().iterator(); while (descriptorIterator.hasNext()) { MonitoredResourceDescriptor descriptor = descriptorIterator.next(); // do something with the descriptor }
- Throws:
LoggingException
- upon failure
-
listMonitoredResourceDescriptorsAsync
com.google.api.core.ApiFuture<com.google.api.gax.paging.AsyncPage<com.google.cloud.MonitoredResourceDescriptor>> listMonitoredResourceDescriptorsAsync(Logging.ListOption... options) Sends a request for listing monitored resource descriptors used by Cloud Logging. This method returns aApiFuture
object to consume the result.Future.get()
returns anAsyncPage
object that can be used to asynchronously handle paginated results. UseLogging.ListOption
to specify the page size or the page token from which to start listing resource descriptors.Example of asynchronously listing monitored resource descriptors, specifying the page size.
ApiFuture<AsyncPage<MonitoredResourceDescriptor>> future = logging .listMonitoredResourceDescriptorsAsync(ListOption.pageSize(100)); // ... AsyncPage<MonitoredResourceDescriptor> descriptors = future.get(); Iterator<MonitoredResourceDescriptor> descriptorIterator = descriptors.iterateAll().iterator(); while (descriptorIterator.hasNext()) { MonitoredResourceDescriptor descriptor = descriptorIterator.next(); // do something with the descriptor }
-
getMetric
Returns the requested metric ornull
if not found.Example of getting a metric.
String metricName = "my_metric_name"; Metric metric = logging.getMetric(metricName); if (metric == null) { // metric was not found }
- Throws:
LoggingException
- upon failure
-
getMetricAsync
Sends a request for getting a metric. This method returns aApiFuture
object to consume the result.Future.get()
returns the requested metric ornull
if not found.Example of asynchronously getting a metric.
String metricName = "my_metric_name"; ApiFuture<Metric> future = logging.getMetricAsync(metricName); // ... Metric metric = future.get(); if (metric == null) { // metric was not found }
- Throws:
LoggingException
- upon failure
-
listMetrics
Lists the metrics. This method returns aPage
object that can be used to consume paginated results. UseLogging.ListOption
to specify the page size or the page token from which to start listing metrics.Example of listing metrics, specifying the page size.
Page<Metric> metrics = logging.listMetrics(ListOption.pageSize(100)); Iterator<Metric> metricIterator = metrics.iterateAll().iterator(); while (metricIterator.hasNext()) { Metric metric = metricIterator.next(); // do something with the metric }
- Throws:
LoggingException
- upon failure
-
listMetricsAsync
com.google.api.core.ApiFuture<com.google.api.gax.paging.AsyncPage<Metric>> listMetricsAsync(Logging.ListOption... options) Sends a request for listing metrics. This method returns aApiFuture
object to consume the result.Future.get()
returns anAsyncPage
object that can be used to asynchronously handle paginated results. UseLogging.ListOption
to specify the page size or the page token from which to start listing metrics.Example of asynchronously listing metrics, specifying the page size.
ApiFuture<AsyncPage<Metric>> future = logging.listMetricsAsync(ListOption.pageSize(100)); // ... AsyncPage<Metric> metrics = future.get(); Iterator<Metric> metricIterator = metrics.iterateAll().iterator(); while (metricIterator.hasNext()) { Metric metric = metricIterator.next(); // do something with the metric }
-
deleteMetric
Deletes the requested metric.Example of deleting a metric.
String metricName = "my_metric_name"; boolean deleted = logging.deleteMetric(metricName); if (deleted) { // the metric was deleted } else { // the metric was not found }
- Returns:
true
if the metric was deleted,false
if it was not found
-
deleteMetricAsync
Sends a request for deleting a metric. This method returns aApiFuture
object to consume the result.Future.get()
returnstrue
if the metric was deleted,false
if it was not found.Example of asynchronously deleting a metric.
String metricName = "my_metric_name"; ApiFuture<Boolean> future = logging.deleteMetricAsync(metricName); // ... boolean deleted = future.get(); if (deleted) { // the metric was deleted } else { // the metric was not found }
-
getExclusion
Gets the description of an exclusion ornull
if not found.Example of getting the description of an exclusion:
String exclusionName = "my_exclusion_name"; Exclusion exclusion = logging.getExclusion(exclusionName); if (exclusion == null) { // exclusion was not found }
- Throws:
LoggingException
- upon failure
-
getExclusionAsync
Sends a request to get the description of an exclusion . This method returns anApiFuture
object to consume the result.Future.get()
returns the requested exclusion ornull
if not found.Example of asynchronously getting the exclusion:
String exclusionName = "my_exclusion_name"; ApiFuture<Exclusion> future = logging.getExclusionAsync(exclusionName); // ... Exclusion exclusion = future.get(); if (exclusion == null) { // exclusion was not found }
- Throws:
LoggingException
- upon failure
-
deleteExclusion
Deletes the requested exclusion.Example of deleting the exclusion:
String exclusionName = "my_exclusion_name"; boolean deleted = logging.deleteExclusion(exclusionName); if (deleted) { // the exclusion was deleted } else { // the exclusion was not found }
- Returns:
true
if the exclusion was deleted,false
if it was not found
-
deleteExclusionAsync
Sends a request to delete an exclusion. This method returns anApiFuture
object to consume the result.Future.get()
returnstrue
if the exclusion was deleted,false
if it was not found.Example of asynchronously deleting the exclusion:
String exclusionName = "my_exclusion_name"; ApiFuture<Boolean> future = logging.deleteExclusionAsync(metricName); // ... boolean deleted = future.get(); if (deleted) { // the exclusion was deleted } else { // the exclusion was not found }
-
listExclusions
Lists the exclusion. This method returns aPage
object that can be used to consume paginated results. UseLogging.ListOption
to specify the page size or the page token from which to start listing exclusion.Example of listing exclusions, specifying the page size:
Page<Exclusion> exclusions = logging.listMetrics(ListOption.pageSize(100)); Iterator<Exclusion> exclusionIterator = exclusions.iterateAll().iterator(); while (exclusionIterator.hasNext()) { Exclusion exclusion = exclusionIterator.next(); // do something with the exclusion }
- Throws:
LoggingException
- upon failure
-
listExclusionsAsync
com.google.api.core.ApiFuture<com.google.api.gax.paging.AsyncPage<Exclusion>> listExclusionsAsync(Logging.ListOption... options) Sends a request for listing exclusions. This method returns anApiFuture
object to consume the result.Future.get()
returns anAsyncPage
object that can be used to asynchronously handle paginated results. UseLogging.ListOption
to specify the page size or the page token from which to start listing exclusions.Example of asynchronously listing exclusions, specifying the page size:
ApiFuture<AsyncPage<Exclusion>> future = logging.listExclusionsAsync(ListOption.pageSize(100)); // ... AsyncPage<Exclusion> exclusions = future.get(); Iterator<Exclusion> exclusionIterator = exclusions.iterateAll().iterator(); while (exclusionIterator.hasNext()) { Exclusion exclusion = exclusionIterator.next(); // do something with the exclusion }
-
flush
void flush()Flushes any pending asynchronous logging writes. Logs are automatically flushed based on time and message count that be configured viaBatchingSettings
, Logs are also flushed if enabled, at or above flush severity, seesetFlushSeverity(com.google.cloud.logging.Severity)
. Logging frameworks require support for an explicit flush. See usage in the java.util.logging handlerLoggingHandler
. -
write
Sends a request to log entries to Cloud Logging. UseLogging.WriteOption.logName(String)
to provide a log name for those entries that do not specify one. UseLogging.WriteOption.resource(MonitoredResource)
to provide a monitored resource for those entries that do not specify one. UseLogging.WriteOption.labels(Map)
to provide some labels to be added to every entry inlogEntries
.Example of writing log entries and providing a default log name and monitored resource.
String logName = "my_log_name"; List<LogEntry> entries = new ArrayList<>(); entries.add(LogEntry.of(StringPayload.of("Entry payload"))); Map<String, Object> jsonMap = new HashMap<>(); jsonMap.put("key", "value"); entries.add(LogEntry.of(JsonPayload.of(jsonMap))); logging.write(entries, WriteOption.logName(logName), WriteOption.resource(MonitoredResource.newBuilder("global").build()));
-
listLogEntries
Lists log entries. This method returns aPage
object that can be used to consume paginated results. UseLogging.EntryListOption.pageSize(int)
to specify the page size. UseLogging.EntryListOption.pageToken(String)
to specify the page token from which to start listing entries. UseLogging.EntryListOption.sortOrder(SortingField, SortingOrder)
to sort log entries according to your preferred order (default is most-recent last). UseLogging.EntryListOption.filter(String)
to filter listed log entries. By default a 24 hour filter is applied.Example of listing log entries for a specific log.
String filter = "logName=projects/my_project_id/logs/my_log_name"; Page<LogEntry> entries = logging.listLogEntries(EntryListOption.filter(filter)); Iterator<LogEntry> entryIterator = entries.iterateAll().iterator(); while (entryIterator.hasNext()) { LogEntry entry = entryIterator.next(); // do something with the entry }
- Throws:
LoggingException
- upon failure
-
listLogEntriesAsync
com.google.api.core.ApiFuture<com.google.api.gax.paging.AsyncPage<LogEntry>> listLogEntriesAsync(Logging.EntryListOption... options) Sends a request for listing log entries. This method returns aApiFuture
object to consume the result.Future.get()
returns anAsyncPage
object that can be used to asynchronously handle paginated results. UseLogging.EntryListOption.pageSize(int)
to specify the page size. UseLogging.EntryListOption.pageToken(String)
to specify the page token from which to start listing entries. UseLogging.EntryListOption.sortOrder(SortingField, SortingOrder)
to sort log entries according to your preferred order (default is most-recent last). UseLogging.EntryListOption.filter(String)
to filter listed log entries. By default a 24 hour filter is applied.Example of asynchronously listing log entries for a specific log.
String filter = "logName=projects/my_project_id/logs/my_log_name"; ApiFuture<AsyncPage<LogEntry>> future = logging.listLogEntriesAsync(EntryListOption.filter(filter)); // ... AsyncPage<LogEntry> entries = future.get(); Iterator<LogEntry> entryIterator = entries.iterateAll().iterator(); while (entryIterator.hasNext()) { LogEntry entry = entryIterator.next(); // do something with the entry }
- Throws:
LoggingException
- upon failure
-
tailLogEntries
@BetaApi("The surface for the tail streaming is not stable yet and may change in the future.") LogEntryServerStream tailLogEntries(Logging.TailOption... options) Sends a request to stream fresh log entries. The method returns aLogEntryServerStream
object to iterate through the returned stream of the log entries. Use EntryListOption#bufferWindow(String)} to specify amount of time to buffer log entries at the server before being returned. entries. UseLogging.TailOption.filter(String)
to filter tailed log entries.Example of streaming log entries for a specific project.
LogEntryServerStream stream = logging.tailLogEntries(TailOption.project("my_project_id")); Iterator<LogEntry> it = stream.iterator(); while (it.hasNext()) { // do something with entry // call stream.cancel(); to stop streaming }
-
populateMetadata
default Iterable<LogEntry> populateMetadata(Iterable<LogEntry> logEntries, com.google.cloud.MonitoredResource customResource, String... exclusionClassPaths) Populates metadata fields of the immutable collection ofLogEntry
items. Only empty fields are populated. TheSourceLocation
is populated only for items with the severity set toSeverity.DEBUG
. The information aboutHttpRequest
, trace and span Id is retrieved usingContextHandler
.- Parameters:
logEntries
- an immutable collection ofLogEntry
items.customResource
- a customized instance of theMonitoredResource
. If this parameter isnull
then the new instance will be generated usingMonitoredResourceUtil.getResource(String, String)
.exclusionClassPaths
- a list of exclussion class path prefixes. If left empty thenSourceLocation
instance is built based on the caller's stack trace information. Otherwise, the information from the firstStackTraceElement
along the call stack which class name does not start with any notnull
exclusion class paths is used.- Returns:
- A collection of
LogEntry
items composed from thelogEntries
parameter with populated metadata fields.
-