private static List<LoggingEnhancer> createEnhancers(Resource resourceType) { List<LoggingEnhancer> enhancers = new ArrayList<>(2); switch (resourceType) { // Trace logging enhancer is supported on GAE Flex and Standard. case GaeAppFlex: enhancers.add( new LabelLoggingEnhancer( APPENGINE_LABEL_PREFIX, Collections.singletonList(Label.InstanceName))); enhancers.add(new TraceLoggingEnhancer(APPENGINE_LABEL_PREFIX)); break; case GaeAppStandard: enhancers.add(new TraceLoggingEnhancer(APPENGINE_LABEL_PREFIX)); break; default: break; } return enhancers; }
@Test public void testTraceEnhancedLogEntry() { 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(TRACE_ENTRY), WriteOption.logName(LOG_NAME), WriteOption.resource(resource), WriteOption.labels(BASE_SEVERITY_MAP)); expectLastCall().once(); replay(options, logging); LoggingEnhancer enhancer = new TraceLoggingEnhancer(); TraceLoggingEnhancer.setCurrentTraceId("projects/projectId/traces/traceId"); 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)); }
private static List<LoggingEnhancer> createEnhancers(Resource resourceType) { List<LoggingEnhancer> enhancers = new ArrayList<>(2); switch (resourceType) { // Trace logging enhancer is supported on GAE Flex and Standard. case GaeAppFlex: enhancers.add( new LabelLoggingEnhancer( APPENGINE_LABEL_PREFIX, Collections.singletonList(Label.InstanceName))); enhancers.add(new TraceLoggingEnhancer(APPENGINE_LABEL_PREFIX)); break; case GaeAppStandard: enhancers.add(new TraceLoggingEnhancer(APPENGINE_LABEL_PREFIX)); break; default: break; } return enhancers; }