@Generated(value="by GAPIC") public class LoggingServiceV2Api extends Object implements AutoCloseable
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.createWithDefaults()) {
String formattedLogName = LoggingServiceV2Api.formatLogName("[PROJECT]", "[LOG]");
loggingServiceV2Api.deleteLog(formattedLogName);
}
Note: close() needs to be called on the loggingServiceV2Api object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of LoggingServiceV2Settings to create(). For example:
LoggingServiceV2Settings loggingServiceV2Settings = LoggingServiceV2Settings.defaultBuilder()
.provideChannelWith(myCredentials)
.build();
LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.create(loggingServiceV2Settings);
| Modifier | Constructor and Description |
|---|---|
protected |
LoggingServiceV2Api(LoggingServiceV2Settings settings)
Constructs an instance of LoggingServiceV2Api, using the given settings.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately
cancelled.
|
static LoggingServiceV2Api |
create(LoggingServiceV2Settings settings)
Constructs an instance of LoggingServiceV2Api, using the given settings.
|
static LoggingServiceV2Api |
createWithDefaults()
Constructs an instance of LoggingServiceV2Api with default settings.
|
void |
deleteLog(String logName)
Deletes a log and all its log entries.
|
com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.DeleteLogRequest,com.google.protobuf.Empty> |
deleteLogCallable()
Deletes a log and all its log entries.
|
static String |
formatLogName(String project,
String log)
Formats a string containing the fully-qualified path to represent
a log resource.
|
static String |
formatProjectName(String project)
Formats a string containing the fully-qualified path to represent
a project resource.
|
LoggingServiceV2Settings |
getSettings() |
com.google.api.gax.core.PageAccessor<com.google.logging.v2.LogEntry> |
listLogEntries(List<String> projectIds,
String filter,
String orderBy)
Lists log entries.
|
com.google.api.gax.core.PageAccessor<com.google.logging.v2.LogEntry> |
listLogEntries(com.google.logging.v2.ListLogEntriesRequest request)
Lists log entries.
|
com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.ListLogEntriesRequest,com.google.logging.v2.ListLogEntriesResponse> |
listLogEntriesCallable()
Lists log entries.
|
com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.ListLogEntriesRequest,com.google.api.gax.core.PageAccessor<com.google.logging.v2.LogEntry>> |
listLogEntriesPagedCallable()
Lists log entries.
|
com.google.api.gax.core.PageAccessor<com.google.api.MonitoredResourceDescriptor> |
listMonitoredResourceDescriptors(com.google.logging.v2.ListMonitoredResourceDescriptorsRequest request)
Lists monitored resource descriptors that are used by Cloud Logging.
|
com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.ListMonitoredResourceDescriptorsRequest,com.google.logging.v2.ListMonitoredResourceDescriptorsResponse> |
listMonitoredResourceDescriptorsCallable()
Lists monitored resource descriptors that are used by Cloud Logging.
|
com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.ListMonitoredResourceDescriptorsRequest,com.google.api.gax.core.PageAccessor<com.google.api.MonitoredResourceDescriptor>> |
listMonitoredResourceDescriptorsPagedCallable()
Lists monitored resource descriptors that are used by Cloud Logging.
|
static String |
parseLogFromLogName(String logName)
Parses the log from the given fully-qualified path which
represents a log resource.
|
static String |
parseProjectFromLogName(String logName)
Parses the project from the given fully-qualified path which
represents a log resource.
|
static String |
parseProjectFromProjectName(String projectName)
Parses the project from the given fully-qualified path which
represents a project resource.
|
com.google.logging.v2.WriteLogEntriesResponse |
writeLogEntries(String logName,
com.google.api.MonitoredResource resource,
Map<String,String> labels,
List<com.google.logging.v2.LogEntry> entries)
Writes log entries to Cloud Logging.
|
com.google.logging.v2.WriteLogEntriesResponse |
writeLogEntries(com.google.logging.v2.WriteLogEntriesRequest request)
Writes log entries to Cloud Logging.
|
com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.WriteLogEntriesRequest,com.google.logging.v2.WriteLogEntriesResponse> |
writeLogEntriesCallable()
Writes log entries to Cloud Logging.
|
protected LoggingServiceV2Api(LoggingServiceV2Settings settings) throws IOException
IOExceptionpublic final LoggingServiceV2Settings getSettings()
public static final String formatProjectName(String project)
public static final String formatLogName(String project, String log)
public static final String parseProjectFromProjectName(String projectName)
public static final String parseProjectFromLogName(String logName)
public static final String parseLogFromLogName(String logName)
public static final LoggingServiceV2Api createWithDefaults() throws IOException
IOExceptionpublic static final LoggingServiceV2Api create(LoggingServiceV2Settings settings) throws IOException
IOExceptionpublic final void deleteLog(String logName)
try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.createWithDefaults()) {
String formattedLogName = LoggingServiceV2Api.formatLogName("[PROJECT]", "[LOG]");
loggingServiceV2Api.deleteLog(formattedLogName);
}
logName - Required. The resource name of the log to delete. Example:
`"projects/my-project/logs/syslog"`.com.google.api.gax.grpc.ApiException - if the remote call failspublic final com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.DeleteLogRequest,com.google.protobuf.Empty> deleteLogCallable()
try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.createWithDefaults()) {
String formattedLogName = LoggingServiceV2Api.formatLogName("[PROJECT]", "[LOG]");
DeleteLogRequest request = DeleteLogRequest.newBuilder()
.setLogName(formattedLogName)
.build();
ListenableFuture<Void> future = loggingServiceV2Api.deleteLogCallable().futureCall(request);
// Do something
future.get();
}
public final com.google.logging.v2.WriteLogEntriesResponse writeLogEntries(String logName, com.google.api.MonitoredResource resource, Map<String,String> labels, List<com.google.logging.v2.LogEntry> entries)
try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.createWithDefaults()) {
String logName = "";
MonitoredResource resource = MonitoredResource.newBuilder().build();
Map<String, String> labels = new HashMap<>();
List<LogEntry> entries = new ArrayList<>();
WriteLogEntriesResponse response = loggingServiceV2Api.writeLogEntries(logName, resource, labels, entries);
}
logName - Optional. A default log resource name for those log entries in `entries`
that do not specify their own `logName`. Example:
`"projects/my-project/logs/syslog"`. See
[LogEntry][google.logging.v2.LogEntry].resource - Optional. A default monitored resource for those log entries in `entries`
that do not specify their own `resource`.labels - Optional. User-defined `key:value` items that are added to
the `labels` field of each log entry in `entries`, except when a log
entry specifies its own `key:value` item with the same key.
Example: `{ "size": "large", "color":"red" }`entries - Required. The log entries to write. The log entries must have values for
all required fields.com.google.api.gax.grpc.ApiException - if the remote call failspublic com.google.logging.v2.WriteLogEntriesResponse writeLogEntries(com.google.logging.v2.WriteLogEntriesRequest request)
try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.createWithDefaults()) {
List<LogEntry> entries = new ArrayList<>();
WriteLogEntriesRequest request = WriteLogEntriesRequest.newBuilder()
.addAllEntries(entries)
.build();
WriteLogEntriesResponse response = loggingServiceV2Api.writeLogEntries(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.grpc.ApiException - if the remote call failspublic final com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.WriteLogEntriesRequest,com.google.logging.v2.WriteLogEntriesResponse> writeLogEntriesCallable()
try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.createWithDefaults()) {
List<LogEntry> entries = new ArrayList<>();
WriteLogEntriesRequest request = WriteLogEntriesRequest.newBuilder()
.addAllEntries(entries)
.build();
ListenableFuture<WriteLogEntriesResponse> future = loggingServiceV2Api.writeLogEntriesCallable().futureCall(request);
// Do something
WriteLogEntriesResponse response = future.get();
}
public final com.google.api.gax.core.PageAccessor<com.google.logging.v2.LogEntry> listLogEntries(List<String> projectIds, String filter, String orderBy)
try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.createWithDefaults()) {
List<String> projectIds = new ArrayList<>();
String filter = "";
String orderBy = "";
for (LogEntry elements : loggingServiceV2Api.listLogEntries(projectIds, filter, orderBy)) {
// doThingsWith(elements);
}
}
projectIds - Required. One or more project IDs or project numbers from which to retrieve
log entries. Examples of a project ID: `"my-project-1A"`, `"1234567890"`.filter - Optional. An [advanced logs filter](/logging/docs/view/advanced_filters).
The filter is compared against all log entries in the projects specified by
`projectIds`. Only entries that match the filter are retrieved. An empty
filter matches all log entries.orderBy - Optional. How the results should be sorted. Presently, the only permitted
values are `"timestamp"` (default) and `"timestamp desc"`. The first
option returns entries in order of increasing values of
`LogEntry.timestamp` (oldest first), and the second option returns entries
in order of decreasing timestamps (newest first). Entries with equal
timestamps are returned in order of `LogEntry.insertId`.com.google.api.gax.grpc.ApiException - if the remote call failspublic final com.google.api.gax.core.PageAccessor<com.google.logging.v2.LogEntry> listLogEntries(com.google.logging.v2.ListLogEntriesRequest request)
try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.createWithDefaults()) {
List<String> projectIds = new ArrayList<>();
ListLogEntriesRequest request = ListLogEntriesRequest.newBuilder()
.addAllProjectIds(projectIds)
.build();
for (LogEntry elements : loggingServiceV2Api.listLogEntries(request)) {
// doThingsWith(elements);
}
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.grpc.ApiException - if the remote call failspublic final com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.ListLogEntriesRequest,com.google.api.gax.core.PageAccessor<com.google.logging.v2.LogEntry>> listLogEntriesPagedCallable()
try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.createWithDefaults()) {
List<String> projectIds = new ArrayList<>();
ListLogEntriesRequest request = ListLogEntriesRequest.newBuilder()
.addAllProjectIds(projectIds)
.build();
ListenableFuture<PageAccessor<LogEntry>> future = loggingServiceV2Api.listLogEntriesPagedCallable().futureCall(request);
// Do something
for (LogEntry elements : future.get()) {
// doThingsWith(elements);
}
}
public final com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.ListLogEntriesRequest,com.google.logging.v2.ListLogEntriesResponse> listLogEntriesCallable()
try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.createWithDefaults()) {
List<String> projectIds = new ArrayList<>();
ListLogEntriesRequest request = ListLogEntriesRequest.newBuilder()
.addAllProjectIds(projectIds)
.build();
while (true) {
ListLogEntriesResponse response = loggingServiceV2Api.listLogEntriesCallable().call(request);
for (LogEntry elements : response.getEntriesList()) {
// doThingsWith(elements);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final com.google.api.gax.core.PageAccessor<com.google.api.MonitoredResourceDescriptor> listMonitoredResourceDescriptors(com.google.logging.v2.ListMonitoredResourceDescriptorsRequest request)
try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.createWithDefaults()) {
ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder()
.build();
for (MonitoredResourceDescriptor elements : loggingServiceV2Api.listMonitoredResourceDescriptors(request)) {
// doThingsWith(elements);
}
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.grpc.ApiException - if the remote call failspublic final com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.ListMonitoredResourceDescriptorsRequest,com.google.api.gax.core.PageAccessor<com.google.api.MonitoredResourceDescriptor>> listMonitoredResourceDescriptorsPagedCallable()
try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.createWithDefaults()) {
ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder()
.build();
ListenableFuture<PageAccessor<MonitoredResourceDescriptor>> future = loggingServiceV2Api.listMonitoredResourceDescriptorsPagedCallable().futureCall(request);
// Do something
for (MonitoredResourceDescriptor elements : future.get()) {
// doThingsWith(elements);
}
}
public final com.google.api.gax.grpc.ApiCallable<com.google.logging.v2.ListMonitoredResourceDescriptorsRequest,com.google.logging.v2.ListMonitoredResourceDescriptorsResponse> listMonitoredResourceDescriptorsCallable()
try (LoggingServiceV2Api loggingServiceV2Api = LoggingServiceV2Api.createWithDefaults()) {
ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder()
.build();
while (true) {
ListMonitoredResourceDescriptorsResponse response = loggingServiceV2Api.listMonitoredResourceDescriptorsCallable().call(request);
for (MonitoredResourceDescriptor elements : response.getResourceDescriptorsList()) {
// doThingsWith(elements);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final void close()
throws Exception
close in interface AutoCloseableExceptionCopyright © 2016 Google. All rights reserved.