Package com.google.cloud.logging
package com.google.cloud.logging
A client for Cloud Logging - Real-time log management and analysis.
Here's a simple usage example for using google-cloud from Compute Engine/App Engine Flexible. This example shows how to write and list log entries. For the complete source code see WriteAndListLogEntries.java.
LoggingOptions options = LoggingOptions.getDefaultInstance();
try(Logging logging = options.getService()) {
LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message"))
.setLogName("test-log")
.setResource(MonitoredResource.builder("global")
.addLabel("project_id", options.getProjectId())
.build())
.build();
logging.write(Collections.singleton(firstEntry));
Page<LogEntry> entries = logging.listLogEntries(
EntryListOption.filter("logName=projects/" + options.getProjectId() + "/logs/test-log"));
Iterator<LogEntry> entryIterator = entries.iterateAll();
while (entryIterator.hasNext()) {
System.out.println(entryIterator.next());
}
}
This second example shows how to use a Logger
to write log entries
to Cloud Logging. The snippet installs a Cloud Logging handler using
LoggingHandler.addHandler(Logger, LoggingHandler)
. Notice that this could also be done through
the logging.properties
file, adding the following line:
com.google.cloud.examples.logging.snippets.AddLoggingHandler.handlers=com.google.cloud.logging.LoggingHandler
For the complete source code see
AddLoggingHandler.java.
Logger logger = Logger.getLogger(AddLoggingHandler.class.getName());
LoggingHandler.addHandler(logger, new LoggingHandler());
logger.warning("test warning");
- See Also:
-
ClassDescriptionClass to hold context attributes including information about and tracing.A builder for objects.Class provides a per-thread storage of the instances.Specifies a set of log entries that are not to be stored in Logging.A builder for
Exclusion
objects.Objects of this class represent information about the (optional) HTTP request associated with a log entry.A builder forHttpRequest
objects.The HTTP request method.Encapsulates implementation of default time filter.Class for specifying resource name of the log to which this log entry belongs (see 'logName' parameter in https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry)A Cloud Logging log entry.A builder forLogEntry
objects.The class implements interface over by iterating through streamed byBidiStream
.The class implementsIterable
interface over .Class for specifying options for listing log entries.Class for specifying options for listing sinks, monitored resources and monitored resource descriptors.Fields according to which log entries can be sorted.Sorting orders available when listing log entries.Class for specifying options for tailing log entries.Class for specifying options for writing log entries.An enhancer for log entries.Logging service exception.An interface for Logging factories.A logging handler that outputs logs generated withLogger
to Cloud Logging.Where to send logs.This class adds some additional Java logging levels for Cloud Logging.Cloud Logging metrics describe logs-based metric.A builder forMetric
objects.Cloud Logging metrics describe logs-based metric.A builder forMetricInfo
objects.Monitored resource construction utilities to detect resource type and add labels.Additional information about a potentially long-running operation with which a log entry is associated.A builder forOperation
objects.Payload<T>A base class for log entry payloads.A log entry's JSON payload.A log entry payload as a protobuf object.A log entry payload as an UTF-8 string.Type for a log entry payload.The severity of the event described in a log entry.Cloud Logging sinks can be used to control the export of your logs.A builder forSink
objects.Cloud Logging sinks can be used to control the export of your logs.A builder forSinkInfo
objects.Class for specifying a Google Cloud Storage bucket as destination for the sink.Class for specifying a Google Cloud BigQuery dataset as destination for the sink.Class for specifying a Google Cloud BigQuery dataset as destination for the sink.Type of destination for Cloud Logging sink.Available log entry formats.Additional information about the source code location that produced the log entry.A builder forSourceLocation
objects.Used to specify the behavior of write calls to the Cloud Logging service.