Skip to content

Commit

Permalink
Update Logging examples, snippets and READMEs to use renamed getters/…
Browse files Browse the repository at this point in the history
…setters/builders
  • Loading branch information
mziccard committed Oct 11, 2016
1 parent aede65b commit 1eb89be
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 64 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ import java.util.Iterator;
LoggingOptions options = LoggingOptions.defaultInstance();
try(Logging logging = options.service()) {
LogEntry firstEntry = LogEntry.builder(StringPayload.of("message"))
.logName("test-log")
.resource(MonitoredResource.builder("global")
LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message"))
.setLogName("test-log")
.setResource(MonitoredResource.builder("global")
.addLabel("project_id", options.projectId())
.build())
.build();
Expand Down
2 changes: 1 addition & 1 deletion TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ uses the `RemoteLoggingHelper` to create a metric.
```java
RemoteLoggingHelper loggingHelper =
RemoteLoggingHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json"));
Logging logging = loggingHelper.options().service();
Logging logging = loggingHelper.getOptions().service();
// Pick a name for the resource with low probability of clashing
String metricName = RemoteLoggingHelper.formatForTest("test-metric");
MetricInfo metricInfo = MetricInfo.of(name, "logName:syslog");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ SinkInfo parse(String... args) throws Exception {
default:
throw new IllegalArgumentException("Second argument must be bucket|dataset|topic.");
}
SinkInfo.Builder builder = SinkInfo.builder(name, destination);
SinkInfo.Builder builder = SinkInfo.newBuilder(name, destination);
if (args.length == 4) {
builder.filter(args[3]);
builder.setFilter(args[3]);
}
return builder.build();
}
Expand Down Expand Up @@ -395,10 +395,10 @@ private static class WriteEntryAction extends LoggingAction<LogEntry> {

@Override
public void run(Logging logging, LogEntry entry) {
MonitoredResource resource = MonitoredResource.builder("global")
MonitoredResource resource = MonitoredResource.newBuilder("global")
.addLabel("project_id", logging.options().projectId())
.build();
LogEntry entryWithResource = entry.toBuilder().resource(resource).build();
LogEntry entryWithResource = entry.toBuilder().setResource(resource).build();
logging.write(Collections.singleton(entryWithResource));
System.out.printf("Written entry %s%n", entryWithResource);
}
Expand All @@ -416,10 +416,10 @@ LogEntry parse(String... args) throws Exception {
for (int i = 3; i < args.length; i += 2) {
labels.put(args[i], args[i + 1]);
}
return LogEntry.builder(StringPayload.of(message))
.logName(logName)
.severity(severity)
.labels(labels)
return LogEntry.newBuilder(StringPayload.of(message))
.setLogName(logName)
.setSeverity(severity)
.setLabels(labels)
.build();
} else {
throw new IllegalArgumentException("Missing required arguments.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public static void main(String... args) throws Exception {
try(Logging logging = LoggingOptions.defaultInstance().service()) {

// Create a metric
MetricInfo metricInfo = MetricInfo.builder("test-metric", "severity >= ERROR")
.description("Log entries with severity higher or equal to ERROR")
MetricInfo metricInfo = MetricInfo.newBuilder("test-metric", "severity >= ERROR")
.setDescription("Log entries with severity higher or equal to ERROR")
.build();
logging.create(metricInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public static void main(String... args) throws Exception {
try(Logging logging = LoggingOptions.defaultInstance().service()) {

// Create a sink to back log entries to a BigQuery dataset
SinkInfo sinkInfo = SinkInfo.builder("test-sink", DatasetDestination.of("test-dataset"))
.filter("severity >= ERROR")
SinkInfo sinkInfo = SinkInfo.newBuilder("test-sink", DatasetDestination.of("test-dataset"))
.setFilter("severity >= ERROR")
.build();
logging.create(sinkInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ public Sink createSinkAsync(String sinkName, String datasetName)
// [VARIABLE "my_dataset"]
public Sink updateSink(String sinkName, String datasetName) {
// [START updateSink]
SinkInfo sinkInfo = SinkInfo.builder(sinkName, DatasetDestination.of(datasetName))
.versionFormat(SinkInfo.VersionFormat.V2)
.filter("severity>=ERROR")
SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName))
.setVersionFormat(SinkInfo.VersionFormat.V2)
.setFilter("severity>=ERROR")
.build();
Sink sink = logging.update(sinkInfo);
// [END updateSink]
Expand All @@ -115,9 +115,9 @@ public Sink updateSink(String sinkName, String datasetName) {
public Sink updateSinkAsync(String sinkName, String datasetName)
throws ExecutionException, InterruptedException {
// [START updateSinkAsync]
SinkInfo sinkInfo = SinkInfo.builder(sinkName, DatasetDestination.of(datasetName))
.versionFormat(SinkInfo.VersionFormat.V2)
.filter("severity>=ERROR")
SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName))
.setVersionFormat(SinkInfo.VersionFormat.V2)
.setFilter("severity>=ERROR")
.build();
Future<Sink> future = logging.updateAsync(sinkInfo);
// ...
Expand Down Expand Up @@ -337,8 +337,8 @@ public Metric createMetricAsync(String metricName)
// [VARIABLE "my_metric_name"]
public Metric updateMetric(String metricName) {
// [START updateMetric]
MetricInfo metricInfo = MetricInfo.builder(metricName, "severity>=ERROR")
.description("new description")
MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR")
.setDescription("new description")
.build();
Metric metric = logging.update(metricInfo);
// [END updateMetric]
Expand All @@ -353,8 +353,8 @@ public Metric updateMetric(String metricName) {
public Metric updateMetricAsync(String metricName)
throws ExecutionException, InterruptedException {
// [START updateMetricAsync]
MetricInfo metricInfo = MetricInfo.builder(metricName, "severity>=ERROR")
.description("new description")
MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR")
.setDescription("new description")
.build();
Future<Metric> future = logging.updateAsync(metricInfo);
// ...
Expand Down Expand Up @@ -480,7 +480,7 @@ public void write(String logName) {
entries.add(LogEntry.of(JsonPayload.of(jsonMap)));
logging.write(entries,
WriteOption.logName(logName),
WriteOption.resource(MonitoredResource.builder("global").build()));
WriteOption.resource(MonitoredResource.newBuilder("global").build()));
// [END write]
}

Expand All @@ -500,7 +500,7 @@ public Future<Void> writeAsync(String logName) {
Future<Void> future = logging.writeAsync(
entries,
WriteOption.logName(logName),
WriteOption.resource(MonitoredResource.builder("global").build()));
WriteOption.resource(MonitoredResource.newBuilder("global").build()));
// [END writeAsync]
return future;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Metric reloadAsync() throws ExecutionException, InterruptedException {
public Metric update() {
// [START update]
Metric updatedMetric = metric.toBuilder()
.description("A more detailed description")
.setDescription("A more detailed description")
.build()
.update();
// [END update]
Expand All @@ -89,7 +89,7 @@ public Metric update() {
public Metric updateAsync() throws ExecutionException, InterruptedException {
// [START updateAsync]
Future<Metric> future = metric.toBuilder()
.description("A more detailed description")
.setDescription("A more detailed description")
.build()
.updateAsync();
// ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Sink reloadAsync() throws ExecutionException, InterruptedException {
public Sink update() {
// [START update]
Sink updatedSink = sink.toBuilder()
.filter("severity<=ERROR")
.setFilter("severity<=ERROR")
.build()
.update();
// [END update]
Expand All @@ -89,7 +89,7 @@ public Sink update() {
public Sink updateAsync() throws ExecutionException, InterruptedException {
// [START updateAsync]
Future<Sink> future = sink.toBuilder()
.filter("severity<=ERROR")
.setFilter("severity<=ERROR")
.build()
.updateAsync();
// ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public static void main(String... args) throws Exception {
try(Logging logging = options.service()) {

// Create a log entry
LogEntry firstEntry = LogEntry.builder(StringPayload.of("message"))
.logName("test-log")
.resource(MonitoredResource.builder("global")
LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message"))
.setLogName("test-log")
.setResource(MonitoredResource.newBuilder("global")
.addLabel("project_id", options.projectId())
.build())
.build();
Expand Down
10 changes: 5 additions & 5 deletions google-cloud-logging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ import com.google.cloud.logging.MetricInfo;
Then, to create the metric, use the following code:

```java
MetricInfo metricInfo = MetricInfo.builder("test-metric", "severity >= ERROR")
.description("Log entries with severity higher or equal to ERROR")
MetricInfo metricInfo = MetricInfo.newBuilder("test-metric", "severity >= ERROR")
.setDescription("Log entries with severity higher or equal to ERROR")
.build();
logging.create(metricInfo);
```
Expand All @@ -131,9 +131,9 @@ import java.util.Collections;
```
Then, to write the log entries, use the following code:
```java
LogEntry firstEntry = LogEntry.builder(StringPayload.of("message"))
.logName("test-log")
.resource(MonitoredResource.builder("global")
LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message"))
.setLogName("test-log")
.setResource(MonitoredResource.builder("global")
.addLabel("project_id", options.projectId())
.build())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ public static EntryListOption filter(String filter) {
* <pre> {@code
* String sinkName = "my_sink_name";
* String datasetName = "my_dataset";
* SinkInfo sinkInfo = SinkInfo.builder(sinkName, DatasetDestination.of(datasetName))
* .versionFormat(SinkInfo.VersionFormat.V2)
* .filter("severity>=ERROR")
* SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName))
* .setVersionFormat(SinkInfo.VersionFormat.V2)
* .setFilter("severity>=ERROR")
* .build();
* Sink sink = logging.update(sinkInfo);
* }</pre>
Expand All @@ -255,9 +255,9 @@ public static EntryListOption filter(String filter) {
* <pre> {@code
* String sinkName = "my_sink_name";
* String datasetName = "my_dataset";
* SinkInfo sinkInfo = SinkInfo.builder(sinkName, DatasetDestination.of(datasetName))
* .versionFormat(SinkInfo.VersionFormat.V2)
* .filter("severity>=ERROR")
* SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName))
* .setVersionFormat(SinkInfo.VersionFormat.V2)
* .setFilter("severity>=ERROR")
* .build();
* Future<Sink> future = logging.updateAsync(sinkInfo);
* // ...
Expand All @@ -274,7 +274,7 @@ public static EntryListOption filter(String filter) {
* <pre> {@code
* String sinkName = "my_sink_name";
* Sink sink = logging.getSink(sinkName);
* if (sink != null) {
* if (sink == null) {
* // sink was not found
* }
* }</pre>
Expand All @@ -293,7 +293,7 @@ public static EntryListOption filter(String filter) {
* Future<Sink> future = logging.getSinkAsync(sinkName);
* // ...
* Sink sink = future.get();
* if (sink != null) {
* if (sink == null) {
* // sink was not found
* }
* }</pre>
Expand Down Expand Up @@ -501,8 +501,8 @@ Future<AsyncPage<MonitoredResourceDescriptor>> listMonitoredResourceDescriptorsA
* <p>Example of updating a metric.
* <pre> {@code
* String metricName = "my_metric_name";
* MetricInfo metricInfo = MetricInfo.builder(metricName, "severity>=ERROR")
* .description("new description")
* MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR")
* .setDescription("new description")
* .build();
* Metric metric = logging.update(metricInfo);
* }</pre>
Expand All @@ -520,8 +520,8 @@ Future<AsyncPage<MonitoredResourceDescriptor>> listMonitoredResourceDescriptorsA
* <p>Example of asynchronously updating a metric.
* <pre> {@code
* String metricName = "my_metric_name";
* MetricInfo metricInfo = MetricInfo.builder(metricName, "severity>=ERROR")
* .description("new description")
* MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR")
* .setDescription("new description")
* .build();
* Future<Metric> future = logging.updateAsync(metricInfo);
* // ...
Expand All @@ -538,7 +538,7 @@ Future<AsyncPage<MonitoredResourceDescriptor>> listMonitoredResourceDescriptorsA
* <pre> {@code
* String metricName = "my_metric_name";
* Metric metric = logging.getMetric(metricName);
* if (metric != null) {
* if (metric == null) {
* // metric was not found
* }
* }</pre>
Expand All @@ -557,7 +557,7 @@ Future<AsyncPage<MonitoredResourceDescriptor>> listMonitoredResourceDescriptorsA
* Future<Metric> future = logging.getMetricAsync(metricName);
* // ...
* Metric metric = future.get();
* if (metric != null) {
* if (metric == null) {
* // metric was not found
* }
* }</pre>
Expand Down Expand Up @@ -662,7 +662,7 @@ Future<AsyncPage<MonitoredResourceDescriptor>> listMonitoredResourceDescriptorsA
* entries.add(LogEntry.of(JsonPayload.of(jsonMap)));
* logging.write(entries,
* WriteOption.logName(logName),
* WriteOption.resource(MonitoredResource.builder("global").build()));
* WriteOption.resource(MonitoredResource.newBuilder("global").build()));
* }</pre>
*
*/
Expand All @@ -688,7 +688,7 @@ Future<AsyncPage<MonitoredResourceDescriptor>> listMonitoredResourceDescriptorsA
* Future<Void> future = logging.writeAsync(
* entries,
* WriteOption.logName(logName),
* WriteOption.resource(MonitoredResource.builder("global").build()));
* WriteOption.resource(MonitoredResource.newBuilder("global").build()));
* }</pre>
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public Future<Metric> reloadAsync() {
* <p>Example of updating the metric's information.
* <pre> {@code
* Metric updatedMetric = metric.toBuilder()
* .description("A more detailed description")
* .setDescription("A more detailed description")
* .build()
* .update();
* }</pre>
Expand All @@ -253,7 +253,7 @@ public Metric update() {
* <p>Example of asynchronously updating the metric's information.
* <pre> {@code
* Future<Metric> future = metric.toBuilder()
* .description("A more detailed description")
* .setDescription("A more detailed description")
* .build()
* .updateAsync();
* // ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public Future<Sink> reloadAsync() {
* <p>Example of updating the sink's information.
* <pre> {@code
* Sink updatedSink = sink.toBuilder()
* .filter("severity<=ERROR")
* .setFilter("severity<=ERROR")
* .build()
* .update();
* }</pre>
Expand All @@ -272,7 +272,7 @@ public Sink update() {
* <p>Example of asynchronously updating the sink's information.
* <pre> {@code
* Future<Sink> future = sink.toBuilder()
* .filter("severity<=ERROR")
* .setFilter("severity<=ERROR")
* .build()
* .updateAsync();
* // ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
* LoggingOptions options = LoggingOptions.defaultInstance();
* try(Logging logging = options.service()) {
*
* LogEntry firstEntry = LogEntry.builder(StringPayload.of("message"))
* .logName("test-log")
* .resource(MonitoredResource.builder("global")
* LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message"))
* .setLogName("test-log")
* .setResource(MonitoredResource.builder("global")
* .addLabel("project_id", options.projectId())
* .build())
* .build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* <p>Before the test:
* <pre> {@code
* RemoteLoggingHelper helper = RemoteLoggingHelper.create();
* Logging logging = helper.options().service();
* Logging logging = helper.getOptions().service();
* } </pre>
*
* <p>Format resource names to avoid name clashes:
Expand Down

0 comments on commit 1eb89be

Please sign in to comment.