Search in sources :

Example 1 with SinkInfo

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));
}
Also used : RemoteLoggingHelper(com.google.cloud.logging.testing.RemoteLoggingHelper) SinkInfo(com.google.cloud.logging.SinkInfo) BeforeClass(org.junit.BeforeClass)

Example 2 with 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);
        }
    }
}
Also used : Logging(com.google.cloud.logging.Logging) Sink(com.google.cloud.logging.Sink) SinkInfo(com.google.cloud.logging.SinkInfo)

Example 3 with SinkInfo

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;
}
Also used : Sink(com.google.cloud.logging.Sink) SinkInfo(com.google.cloud.logging.SinkInfo)

Example 4 with SinkInfo

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;
}
Also used : Sink(com.google.cloud.logging.Sink) SinkInfo(com.google.cloud.logging.SinkInfo)

Example 5 with SinkInfo

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;
}
Also used : Sink(com.google.cloud.logging.Sink) SinkInfo(com.google.cloud.logging.SinkInfo)

Aggregations

SinkInfo (com.google.cloud.logging.SinkInfo)6 Sink (com.google.cloud.logging.Sink)5 Logging (com.google.cloud.logging.Logging)1 RemoteLoggingHelper (com.google.cloud.logging.testing.RemoteLoggingHelper)1 BeforeClass (org.junit.BeforeClass)1