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));
}
Aggregations