List of usage examples for com.google.common.base Supplier toString
public String toString()
From source file:nebula.plugin.metrics.collector.LoggingCollector.java
/** * Configure a logback filter to capture all root logging events. * Avoids having to depend on a particular Gradle logging level being set. Gradle's logging is such that * encoders/layouts/etc aren't an option and LogbackLoggingConfigurer.doConfigure() adds a TurboFilter which * prevents us getting at those events, so we re-wire the filters so ours comes first. * * @param dispatcherSupplier the dispatcher supplier * @param extension the extension *///from w w w.j a v a2s . com public static void configureCollection(final Supplier<MetricsDispatcher> dispatcherSupplier, final MetricsPluginExtension extension) { checkNotNull(dispatcherSupplier); checkNotNull(extension); final BlockingQueue<LogEvent> logEvents = new LinkedBlockingQueue<>(); OutputEventListenerBackedLoggerContext context = (OutputEventListenerBackedLoggerContext) LoggerFactory .getILoggerFactory(); // setting LogLevel to DEBUG forces stdout messages to be classified as DEBUG events, which are then discarded and never shown. //context.setLevel(LogLevel.DEBUG); OutputEventListener originalListener = context.getOutputEventListener(); if (dispatcherSupplier.toString().startsWith("Dummy proxy")) { // Horrible coupled logic, but we need to keep the Guava nulls testers out of here return; } if (originalListener.getClass().getName().startsWith("nebula.plugin.metrics.collector.LoggingCollector")) { LOGGER.error( "Output event listener is already wrapped. A previous build against this daemon did not clean reset the logging collection. Please report this bug"); return; } OutputEventListener listener = new WrappedOutputEventListener(originalListener) { @Override public void onOutput(OutputEvent outputEvent) { if (IN_LISTENER.get()) { return; } IN_LISTENER.set(true); try { if (outputEvent instanceof LogEvent) { LogEvent logEvent = (LogEvent) outputEvent; if (levelGreaterOrEqual(outputEvent, extension.getLogLevel()) || logEvent.getMessage().startsWith(MetricsLoggerFactory.LOGGING_PREFIX)) { MetricsDispatcher dispatcher = dispatcherSupplier.get(); if (dispatcher.state() == Service.State.NEW || dispatcher.state() == Service.State.STARTING) { logEvents.add(logEvent); } else { if (!logEvents.isEmpty()) { List<LogEvent> drainedEvents = Lists.newArrayListWithCapacity(logEvents.size()); logEvents.drainTo(drainedEvents); if (!drainedEvents.isEmpty()) { dispatcher.logEvents(drainedEvents); } } dispatcher.logEvent(logEvent); } } } super.onOutput(outputEvent); } finally { IN_LISTENER.set(false); } } }; context.setOutputEventListener(listener); }