ch.qos.logback.core.spi.ContextAware Java Examples

The following examples show how to use ch.qos.logback.core.spi.ContextAware. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FlumeAvroManager.java    From logback-flume-appender with MIT License 6 votes vote down vote up
public static FlumeAvroManager create(
    final List<RemoteFlumeAgent> agents,
    final Properties overrides,
    final Integer batchSize,
    final Long reportingWindow,
    final Integer reporterMaxThreadPoolSize,
    final Integer reporterMaxQueueSize,
    final ContextAware context) {

    if (agents != null && agents.size() > 0) {
      Properties props = buildFlumeProperties(agents);
      props.putAll(overrides);
      return new FlumeAvroManager(props, reportingWindow, batchSize, reporterMaxThreadPoolSize, reporterMaxQueueSize, context);
    } else {
      context.addError("No valid agents configured");
    }

  return null;
}
 
Example #2
Source File: FlumeAvroManager.java    From logback-flume-appender with MIT License 6 votes vote down vote up
private FlumeAvroManager(final Properties props,
                         final Long reportingWindowReq,
                         final Integer batchSizeReq,
                         final Integer reporterMaxThreadPoolSizeReq,
                         final Integer reporterMaxQueueSizeReq,
                         final ContextAware context) {
  this.loggingContext = context;

  final int reporterMaxThreadPoolSize = reporterMaxThreadPoolSizeReq == null ?
          DEFAULT_REPORTER_MAX_THREADPOOL_SIZE : reporterMaxThreadPoolSizeReq;
  final int reporterMaxQueueSize = reporterMaxQueueSizeReq == null ?
          DEFAULT_REPORTER_MAX_QUEUE_SIZE : reporterMaxQueueSizeReq;

  this.reporter = new EventReporter(props, loggingContext, reporterMaxThreadPoolSize, reporterMaxQueueSize);
  this.evQueue = new ArrayBlockingQueue<Event>(1000);
  final long reportingWindow = hamonizeReportingWindow(reportingWindowReq);
  final int batchSize = batchSizeReq == null ? DEFAULT_BATCH_SIZE : batchSizeReq;
  this.asyncThread = new AsyncThread(evQueue, batchSize, reportingWindow);
  loggingContext.addInfo("Created a new flume agent with properties: " + props.toString());
  asyncThread.start();
}
 
Example #3
Source File: KonkerStatusListenerConfigHelper.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
private static void initAndAddListener(KonkerLoggerContext loggerContext, StatusListener listener) {
    if(listener != null) {
        if(listener instanceof ContextAware) {
            ((ContextAware)listener).setContext(loggerContext);
        }

        if(listener instanceof LifeCycle) {
            ((LifeCycle)listener).start();
        }

        loggerContext.getStatusManager().add(listener);
    }

}
 
Example #4
Source File: ChildConverterContextInjector.java    From cf-java-logging-support with Apache License 2.0 5 votes vote down vote up
private void inject(Context context, Converter<ILoggingEvent> head, boolean injectAll) {
	for (Converter<ILoggingEvent> c = head; c != null; c = c.getNext()) {
		if (c instanceof CompositeConverter<?>) {
			Converter<ILoggingEvent> childConverter = ((CompositeConverter<ILoggingEvent>) c).getChildConverter();
			inject(context, childConverter, true);
		}
		if (injectAll && c instanceof ContextAware) {
			((ContextAware) c).setContext(context);
		}
	}
}
 
Example #5
Source File: EventReporter.java    From logback-flume-appender with MIT License 5 votes vote down vote up
public EventReporter(final Properties properties, final ContextAware context,
                     final int maximumThreadPoolSize, final int maxQueueSize) {
  BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<Runnable>(maxQueueSize);
  this.connectionProps = properties;
  this.loggingContext = context;

  int corePoolSize = 1;
  TimeUnit threadKeepAliveUnits = TimeUnit.SECONDS;
  int threadKeepAliveTime = 30;
  RejectedExecutionHandler handler = new ThreadPoolExecutor.AbortPolicy();

  this.es = new ThreadPoolExecutor(corePoolSize, maximumThreadPoolSize, threadKeepAliveTime,
          threadKeepAliveUnits, blockingQueue, handler);
}
 
Example #6
Source File: SpacedLogbackSystem.java    From spring-cloud-formula with Apache License 2.0 4 votes vote down vote up
public void start(LifeCycle lifeCycle) {
    if (lifeCycle instanceof ContextAware) {
        ((ContextAware) lifeCycle).setContext(context);
    }
    lifeCycle.start();
}
 
Example #7
Source File: LogbackConfigurator.java    From super-cloudops with Apache License 2.0 4 votes vote down vote up
public void start(LifeCycle lifeCycle) {
	if (lifeCycle instanceof ContextAware) {
		((ContextAware) lifeCycle).setContext(this.context);
	}
	lifeCycle.start();
}