/** * Returns an option to sort log entries. If not specified, log entries are sorted in ascending * (most-recent last) order with respect to the {@link LogEntry#getTimestamp()} value. */ public static EntryListOption sortOrder(SortingField field, SortingOrder order) { return new EntryListOption(OptionType.ORDER_BY, field.selector() + ' ' + order.selector()); }
/** Example of updating the metric's information. */ // [TARGET update()] public Metric update() { // [START update] Metric updatedMetric = metric.toBuilder().setDescription("A more detailed description").build().update(); // [END update] return updatedMetric; }
/** Example of updating a metric. */ // [TARGET update(MetricInfo)] // [VARIABLE "my_metric_name"] public Metric updateMetric(String metricName) { // [START updateMetric] MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR") .setDescription("new description") .build(); Metric metric = logging.update(metricInfo); // [END updateMetric] return metric; }
@Test public void testUpdate() { initializeExpectedSink(2); SinkInfo updatedInfo = SINK_INFO.toBuilder().setFilter(NEW_FILTER).build(); Sink expectedSink = new Sink(serviceMockReturnsOptions, new SinkInfo.BuilderImpl(updatedInfo)); expect(logging.getOptions()).andReturn(mockOptions).times(2); expect(logging.update(expectedSink)).andReturn(expectedSink); replay(logging); initializeSink(); Sink updatedSink = sink.toBuilder().setFilter(NEW_FILTER).build().update(); compareSink(expectedSink, updatedSink); }
/** * Creates a {@code LogEntry} object given the log name, the monitored resource and the entry * payload. */ public static LogEntry of(String logName, MonitoredResource resource, Payload<?> payload) { return newBuilder(payload).setLogName(logName).setResource(resource).build(); }
@Test public void testReload() { initializeExpectedSink(2); SinkInfo updatedInfo = SINK_INFO.toBuilder().setFilter(NEW_FILTER).build(); Sink expectedSink = new Sink(serviceMockReturnsOptions, new SinkInfo.BuilderImpl(updatedInfo)); expect(logging.getOptions()).andReturn(mockOptions); expect(logging.getSink(NAME)).andReturn(expectedSink); replay(logging); initializeSink(); Sink updatedSink = sink.reload(); compareSink(expectedSink, updatedSink); }
@Test public void testUpdateNonExistingMetric() { String name = formatForTest("test-update-non-existing-metric"); MetricInfo metricInfo = MetricInfo.newBuilder(name, "severity>=ERROR").setDescription("description").build(); assertNull(logging().getMetric(name)); Metric metric = logging().update(metricInfo); assertEquals(name, metric.getName()); assertEquals("severity>=ERROR", metric.getFilter()); assertEquals("description", metric.getDescription()); assertTrue(metric.delete()); }
/** Creates a {@code LogEntry} object given the entry payload. */ public static LogEntry of(Payload<?> payload) { return newBuilder(payload).build(); }
@Test public void testToAndFromPb_NoProjectId() { DatasetDestination datasetDestination = DatasetDestination.of("dataset"); SinkInfo sinkInfo = SinkInfo.of("name", DATASET_DESTINATION); compareSinkInfo( sinkInfo, SinkInfo.fromPb(SinkInfo.of("name", datasetDestination).toPb("project"))); TopicDestination topicDestination = TopicDestination.of("topic"); sinkInfo = SinkInfo.of("name", TOPIC_DESTINATION); compareSinkInfo( sinkInfo, SinkInfo.fromPb(SinkInfo.of("name", topicDestination).toPb("project"))); }
static Sink fromPb(Logging logging, LogSink sinkPb) { SinkInfo sinkInfo = SinkInfo.fromPb(sinkPb); return new Sink(logging, new BuilderImpl(sinkInfo)); }
/** * Sets minimum logging level to log immediately and flush any pending writes. * * @param flushLevel minimum log level to trigger flush */ public void setFlushLevel(Level flushLevel) { this.flushLevel = flushLevel; getLogging().setFlushSeverity(severityFor(flushLevel)); }
static Metric fromPb(Logging logging, LogMetric metricPb) { MetricInfo metricInfo = MetricInfo.fromPb(metricPb); return new Metric(logging, new BuilderImpl(metricInfo)); }
/** Returns a default {@code LoggingOptions} instance. */ public static LoggingOptions getDefaultInstance() { return newBuilder().build(); }
@Override public void enhanceLogEntry(com.google.cloud.logging.LogEntry.Builder builder) { String traceId = getCurrentTraceId(); if (traceId != null) { builder.setTrace(traceId); } } }
/** Example of creating a metric for logs with severity higher or equal to ERROR. */ // [TARGET create(MetricInfo)] // [VARIABLE "my_metric_name"] public Metric createMetric(String metricName) { // [START createMetric] MetricInfo metricInfo = MetricInfo.of(metricName, "severity>=ERROR"); Metric metric = logging.create(metricInfo); // [END createMetric] return metric; }
/** * Sets synchronicity of logging writes. By default, writes are asynchronous. * * @param synchronicity {@link Synchronicity} */ public void setSynchronicity(Synchronicity synchronicity) { getLogging().setWriteSynchronicity(synchronicity); }
/** * Returns a {@code Operation} object given the operation and producer identifiers. The * combination of producer and id must be globally unique. */ public static Operation of(String id, String producer) { return newBuilder(id, producer).build(); }
MonitoredResource getMonitoredResource(String projectId) { String resourceType = getProperty(RESOURCE_TYPE_TAG, ""); return MonitoredResourceUtil.getResource(projectId, resourceType); }
Synchronicity getSynchronicity() { String synchronicityStr = getProperty(SYNCHRONICITY_TAG); try { return Synchronicity.valueOf(synchronicityStr); } catch (Exception ex) { // If we cannot create the Synchronicity we fall back to default value } return Synchronicity.ASYNC; }