use of com.google.cloud.logging.SinkInfo in project google-cloud-java by GoogleCloudPlatform.
the class ITSinkSnippets method beforeClass.
@BeforeClass
public static void beforeClass() {
RemoteLoggingHelper helper = RemoteLoggingHelper.create();
logging = helper.getOptions().getService();
SinkInfo sinkInfo = SinkInfo.newBuilder(SINK_NAME, Destination.DatasetDestination.of(DESTINATION)).setFilter(SINK_FILTER).build();
sinkSnippets = new SinkSnippets(logging.create(sinkInfo));
}
use of com.google.cloud.logging.SinkInfo in project google-cloud-java by GoogleCloudPlatform.
the class CreateAndListSinks method main.
public static void main(String... args) throws Exception {
// Credentials are inferred from the environment
try (Logging logging = LoggingOptions.getDefaultInstance().getService()) {
// Create a sink to back log entries to a BigQuery dataset
SinkInfo sinkInfo = SinkInfo.newBuilder("test-sink", DatasetDestination.of("test-dataset")).setFilter("severity >= ERROR").build();
logging.create(sinkInfo);
// List sinks
Page<Sink> sinks = logging.listSinks();
for (Sink sink : sinks.iterateAll()) {
System.out.println(sink);
}
}
}
use of com.google.cloud.logging.SinkInfo in project google-cloud-java by GoogleCloudPlatform.
the class LoggingSnippets method updateSink.
/**
* Example of updating a sink.
*/
// [TARGET update(SinkInfo)]
// [VARIABLE "my_sink_name"]
// [VARIABLE "my_dataset"]
public Sink updateSink(String sinkName, String datasetName) {
// [START updateSink]
SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName)).setVersionFormat(SinkInfo.VersionFormat.V2).setFilter("severity>=ERROR").build();
Sink sink = logging.update(sinkInfo);
// [END updateSink]
return sink;
}
use of com.google.cloud.logging.SinkInfo in project google-cloud-java by GoogleCloudPlatform.
the class LoggingSnippets method updateSinkAsync.
/**
* Example of asynchronously updating a sink.
*/
// [TARGET updateAsync(SinkInfo)]
// [VARIABLE "my_sink_name"]
// [VARIABLE "my_dataset"]
public Sink updateSinkAsync(String sinkName, String datasetName) throws ExecutionException, InterruptedException {
// [START updateSinkAsync]
SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName)).setVersionFormat(SinkInfo.VersionFormat.V2).setFilter("severity>=ERROR").build();
Future<Sink> future = logging.updateAsync(sinkInfo);
// ...
Sink sink = future.get();
// [END updateSinkAsync]
return sink;
}
use of com.google.cloud.logging.SinkInfo in project google-cloud-java by GoogleCloudPlatform.
the class LoggingSnippets method createSink.
/**
* Example of creating a sink to export logs to a BigQuery dataset (in the
* {@link LoggingOptions#getProjectId()} project).
*/
// [TARGET create(SinkInfo)]
// [VARIABLE "my_sink_name"]
// [VARIABLE "my_dataset"]
public Sink createSink(String sinkName, String datasetName) {
// [START createSink]
SinkInfo sinkInfo = SinkInfo.of(sinkName, DatasetDestination.of(datasetName));
Sink sink = logging.create(sinkInfo);
// [END createSink]
return sink;
}
Aggregations