ch.qos.logback.core.Appender.setContext()方法的使用及代码示例

x33g5p2x  于11个月前 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(35)

本文整理了Java中ch.qos.logback.core.Appender.setContext()方法的一些代码示例,展示了Appender.setContext()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Appender.setContext()方法的具体详情如下:
包路径:ch.qos.logback.core.Appender
类名称:Appender
方法名:setContext

Appender.setContext介绍

暂无

代码示例

代码示例来源:origin: ctripcorp/apollo

private void tryConfigCLogging() throws Exception {
 String appId = Foundation.app().getAppId();
 if (Strings.isNullOrEmpty(appId)) {
  logger.warn("App id is null or empty!");
  return;
 }
 LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
 Class clazz = Class.forName(cLoggingAppenderClass);
 Appender cLoggingAppender = (Appender) clazz.newInstance();
 ReflectionUtils.findMethod(clazz, "setAppId", String.class).invoke(cLoggingAppender, appId);
 ReflectionUtils.findMethod(clazz, "setServerIp", String.class)
   .invoke(cLoggingAppender, cloggingUrl());
 ReflectionUtils.findMethod(clazz, "setServerPort", int.class)
   .invoke(cLoggingAppender, Integer.parseInt(cloggingPort()));
 cLoggingAppender.setName("CentralLogging");
 cLoggingAppender.setContext(loggerContext);
 cLoggingAppender.start();
 ch.qos.logback.classic.Logger logger =
   (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("root");
 logger.addAppender(cLoggingAppender);
}

代码示例来源:origin: camunda/camunda-bpm-platform

ch.qos.logback.core.Appender.class, context);
appender.setContext(context);

代码示例来源:origin: co.cask.cdap/cdap-watchdog

@Override
public void setContext(Context context) {
 delegate.setContext(context);
}

代码示例来源:origin: caskdata/cdap

@Override
public void setContext(Context context) {
 delegate.setContext(context);
}

代码示例来源:origin: mozafari/verdictdb

public void addAppender(Appender<ILoggingEvent> appender) {
 if (logger instanceof ch.qos.logback.classic.Logger) {
  appender.setContext(((ch.qos.logback.classic.Logger) logger).getLoggerContext());
  ((ch.qos.logback.classic.Logger) logger).addAppender(appender);
 }
}

代码示例来源:origin: org.openmicroscopy/ome-common

public static synchronized void enableIJLogging(boolean debug,
  Appender<ILoggingEvent> appender) {
  try {

   Object logger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
   if (!(logger instanceof Logger)) return;

   Logger root = (Logger) logger;

   if (debug) {
    root.setLevel(Level.DEBUG);
   }
   appender.setContext(root.getLoggerContext());
   root.addAppender(appender);
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}

代码示例来源:origin: ome/formats-common

public static synchronized void enableIJLogging(boolean debug,
  Appender<ILoggingEvent> appender) {
  try {

   Object logger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
   if (!(logger instanceof Logger)) return;

   Logger root = (Logger) logger;

   if (debug) {
    root.setLevel(Level.DEBUG);
   }
   appender.setContext(root.getLoggerContext());
   root.addAppender(appender);
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}

代码示例来源:origin: Audiveris/audiveris

/**
 * Add a specific appender meant for GUI log pane.
 * To be called only when running with a GUI.
 */
public static void addGuiAppender ()
{
  // GUI (filtered in LogGuiAppender)
  LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
  Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(
      Logger.ROOT_LOGGER_NAME);
  Appender guiAppender = new LogGuiAppender();
  guiAppender.setName("GUI");
  guiAppender.setContext(loggerContext);
  guiAppender.start();
  root.addAppender(guiAppender);
}

代码示例来源:origin: dstl/baleen

/**
  * Build a new appender for the specified context and encoder (where required).
  *
  * @param context The logger context
  * @param encoder The encoder to use (if that is possible for the specific appender)
  * @return The new appender
  */
 @Override
 public final Appender<ILoggingEvent> build(
   LoggerContext context, Encoder<ILoggingEvent> encoder) {
  Appender<ILoggingEvent> appender = createAppender(context, encoder);
  appender.setName(name);
  appender.setContext(context);

  if (filters != null) {
   filters.forEach(appender::addFilter);
  }

  return appender;
 }
}

代码示例来源:origin: uk.gov.dstl.baleen/baleen-core

/**
  * Build a new appender for the specified context and encoder (where required).
  *
  * @param context The logger context
  * @param encoder The encoder to use (if that is possible for the specific appender)
  * @return The new appender
  */
 @Override
 public final Appender<ILoggingEvent> build(
   LoggerContext context, Encoder<ILoggingEvent> encoder) {
  Appender<ILoggingEvent> appender = createAppender(context, encoder);
  appender.setName(name);
  appender.setContext(context);

  if (filters != null) {
   filters.forEach(appender::addFilter);
  }

  return appender;
 }
}

代码示例来源:origin: net.logstash.logback/logstash-logback-encoder

private void startDelegateAppenders() {
  for (Iterator<Appender<Event>> appenderIter = appenders.iteratorForAppenders(); appenderIter.hasNext();) {
    Appender<Event> appender = appenderIter.next();
    if (appender.getContext() == null) {
      appender.setContext(getContext());
    }
    if (!appender.isStarted()) {
      appender.start();
    }
  }
}

代码示例来源:origin: protegeproject/protege

public void bind() {
    applyPreferences();
  Logger rootLogger = getRootLogger();
  appender.setContext(rootLogger.getLoggerContext());
  appender.start();        
  rootLogger.addAppender(appender);        
}

代码示例来源:origin: com.paypal.butterfly/butterfly-cli

@Override
  public void setVerboseMode(boolean verboseMode) {
    this.verboseMode = verboseMode;

    if (verboseMode) {
      PatternLayoutEncoder patternLayoutEncoder = new PatternLayoutEncoder();
      patternLayoutEncoder.setPattern("[%d{HH:mm:ss.SSS}] [%highlight(%level)] %msg%n");
      patternLayoutEncoder.setContext(loggerContext);
      patternLayoutEncoder.start();

      Appender<ILoggingEvent> consoleAppender = new ConsoleAppender();
      ((OutputStreamAppender) consoleAppender).setEncoder(patternLayoutEncoder);
      consoleAppender.setContext(loggerContext);
      consoleAppender.start();

      loggerContext.getLogger("com.paypal.butterfly.cli").detachAppender("CONSOLE");
      loggerContext.getLogger("ROOT").addAppender(consoleAppender);
//        } else {
      // TODO
    }
  }

代码示例来源:origin: qos-ch/logback-extensions

private Appender<ILoggingEvent> getDelegate() {
  ApplicationContext context = ApplicationContextHolder.getApplicationContext();
  try {
    @SuppressWarnings("unchecked")
    Appender<ILoggingEvent> appender = context.getBean(beanName, Appender.class);
    appender.setContext(getContext());
    if (!appender.isStarted()) {
      appender.start();
    }
    return appender;
  } catch (NoSuchBeanDefinitionException e) {
    stop();
    addError("The ApplicationContext does not contain an Appender named [" + beanName +
        "]. This delegating appender will now stop processing events.", e);
  }
  return null;
}

代码示例来源:origin: org.openmicroscopy/ome-common

layout.start();
defaultAppender.setContext(context);
((ConsoleAppender) defaultAppender).setEncoder(layout);
defaultAppender.start();

代码示例来源:origin: io.virtdata/virtdata-lib-realer

appender.setContext(context);

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

appender.setContext(context);

代码示例来源:origin: tony19/logback-android

ch.qos.logback.core.Appender.class, context);
appender.setContext(context);

代码示例来源:origin: getheimdall/heimdall

@PostConstruct
public void onStartUp() {
  if (property.getMongo().getEnabled()) {
        LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger logger = (Logger) LoggerFactory.getLogger("mongo");
    logger.setAdditive(false);
    String zoneId = property.getMongo().getZoneId() != null ? property.getMongo().getZoneId() : DEFAULT_ZONE_ID;
    // Creating custom MongoDBAppender
    Appender<ILoggingEvent> appender;
    if (property.getMongo().getUrl() != null) {
       appender = new MongoDBAppender(property.getMongo().getUrl(), property.getMongo().getDataBase(), property.getMongo().getCollection(), zoneId);
    } else {
       appender = new MongoDBAppender(property.getMongo().getServerName(), property.getMongo().getPort(), property.getMongo().getDataBase(), property.getMongo().getCollection(), zoneId);
    }
    appender.setContext(lc);
    appender.start();
    // Creating AsyncAppender
    int queueSize = (property.getMongo().getQueueSize() != null) ? property.getMongo().getQueueSize().intValue() : DEFAULT_QUEUE_SIZE;
    AsyncAppender asyncAppender = new AsyncAppender();
    asyncAppender.setQueueSize(queueSize);
    if (property.getMongo().getDiscardingThreshold() != null) {            	 
      asyncAppender.setDiscardingThreshold(property.getMongo().getDiscardingThreshold().intValue());
    }
    asyncAppender.addAppender(appender);
    asyncAppender.start();
    logger.addAppender(asyncAppender);
 }
}

代码示例来源:origin: tony19/logback-android

@Test
 public void testNoStart() {
  Appender<E> appender = getAppender();
  appender.setContext(context);
  appender.setName("doh");
  // is null OK?
  appender.doAppend(null);
  StatusChecker checker = new StatusChecker(context.getStatusManager());
  StatusPrinter.print(context);
  checker.assertContainsMatch("Attempted to append to non started appender \\[doh\\].");
 }
}

相关文章