Search in sources :

Example 1 with Builder

use of com.google.cloud.logging.LogEntry.Builder in project google-cloud-java by GoogleCloudPlatform.

the class LoggingHandlerTest method testEnhancedLogEntry.

@Test
public void testEnhancedLogEntry() {
    expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
    expect(options.getService()).andReturn(logging);
    MonitoredResource resource = MonitoredResource.of("custom", ImmutableMap.<String, String>of());
    logging.setFlushSeverity(Severity.ERROR);
    expectLastCall().once();
    logging.setWriteSynchronicity(Synchronicity.ASYNC);
    expectLastCall().once();
    logging.write(ImmutableList.of(FINEST_ENHANCED_ENTRY), WriteOption.logName(LOG_NAME), WriteOption.resource(resource), WriteOption.labels(BASE_SEVERITY_MAP));
    expectLastCall().once();
    replay(options, logging);
    LoggingEnhancer enhancer = new LoggingEnhancer() {

        @Override
        public void enhanceLogEntry(Builder builder) {
            builder.addLabel("enhanced", "true");
        }
    };
    Handler handler = new LoggingHandler(LOG_NAME, options, resource, Collections.singletonList(enhancer));
    handler.setLevel(Level.ALL);
    handler.setFormatter(new TestFormatter());
    handler.publish(newLogRecord(Level.FINEST, MESSAGE));
}
Also used : Builder(com.google.cloud.logging.LogEntry.Builder) MonitoredResource(com.google.cloud.MonitoredResource) Handler(java.util.logging.Handler) Test(org.junit.Test)

Aggregations

MonitoredResource (com.google.cloud.MonitoredResource)1 Builder (com.google.cloud.logging.LogEntry.Builder)1 Handler (java.util.logging.Handler)1 Test (org.junit.Test)1