コード例 #1
0
  @Override
  public void start() {
    final Map<String, Appender> map = config.getAppenders();
    final List<AppenderControl> appenders = new ArrayList<>();
    for (final AppenderRef appenderRef : appenderRefs) {
      if (map.containsKey(appenderRef.getRef())) {
        appenders.add(
            new AppenderControl(
                map.get(appenderRef.getRef()), appenderRef.getLevel(), appenderRef.getFilter()));
      } else {
        LOGGER.error("No appender named {} was configured", appenderRef);
      }
    }
    if (errorRef != null) {
      if (map.containsKey(errorRef)) {
        errorAppender = new AppenderControl(map.get(errorRef), null, null);
      } else {
        LOGGER.error(
            "Unable to set up error Appender. No appender named {} was configured", errorRef);
      }
    }
    if (appenders.size() > 0) {
      thread = new AsyncThread(appenders, queue);
      thread.setName("AsyncAppender-" + getName());
    } else if (errorRef == null) {
      throw new ConfigurationException("No appenders are available for AsyncAppender " + getName());
    }

    thread.start();
    super.start();
  }
コード例 #2
0
 @Override
 public void stop() {
   super.stop();
   LOGGER.trace("AsyncAppender stopping. Queue still has {} events.", queue.size());
   thread.shutdown();
   try {
     thread.join();
   } catch (final InterruptedException ex) {
     LOGGER.warn("Interrupted while stopping AsyncAppender {}", getName());
   }
   LOGGER.trace("AsyncAppender stopped. Queue has {} events.", queue.size());
 }
コード例 #3
0
  @Override
  public boolean stop(final long timeout, final TimeUnit timeUnit) {
    setStopping();
    super.stop(timeout, timeUnit, false);
    LOGGER.trace("AsyncAppender stopping. Queue still has {} events.", queue.size());
    thread.shutdown();
    try {
      thread.join(shutdownTimeout);
    } catch (final InterruptedException ex) {
      LOGGER.warn("Interrupted while stopping AsyncAppender {}", getName());
    }
    LOGGER.trace("AsyncAppender stopped. Queue has {} events.", queue.size());

    if (DiscardingAsyncQueueFullPolicy.getDiscardCount(asyncQueueFullPolicy) > 0) {
      LOGGER.trace(
          "AsyncAppender: {} discarded {} events.",
          asyncQueueFullPolicy,
          DiscardingAsyncQueueFullPolicy.getDiscardCount(asyncQueueFullPolicy));
    }
    setStopped();
    return true;
  }
コード例 #4
0
ファイル: SyslogAppender.java プロジェクト: chums122/Spigot
 @PluginFactory
 public static SyslogAppender createAppender(
     @PluginAttribute("host") String host,
     @PluginAttribute("port") String portNum,
     @PluginAttribute("protocol") String protocol,
     @PluginAttribute("reconnectionDelay") String delay,
     @PluginAttribute("immediateFail") String immediateFail,
     @PluginAttribute("name") String name,
     @PluginAttribute("immediateFlush") String immediateFlush,
     @PluginAttribute("ignoreExceptions") String ignore,
     @PluginAttribute("facility") String facility,
     @PluginAttribute("id") String id,
     @PluginAttribute("enterpriseNumber") String ein,
     @PluginAttribute("includeMDC") String includeMDC,
     @PluginAttribute("mdcId") String mdcId,
     @PluginAttribute("mdcPrefix") String mdcPrefix,
     @PluginAttribute("eventPrefix") String eventPrefix,
     @PluginAttribute("newLine") String includeNL,
     @PluginAttribute("newLineEscape") String escapeNL,
     @PluginAttribute("appName") String appName,
     @PluginAttribute("messageId") String msgId,
     @PluginAttribute("mdcExcludes") String excludes,
     @PluginAttribute("mdcIncludes") String includes,
     @PluginAttribute("mdcRequired") String required,
     @PluginAttribute("format") String format,
     @PluginElement("Filters") Filter filter,
     @PluginConfiguration Configuration config,
     @PluginAttribute("charset") String charsetName,
     @PluginAttribute("exceptionPattern") String exceptionPattern,
     @PluginElement("LoggerFields") LoggerFields[] loggerFields,
     @PluginAttribute("advertise") String advertise) {
   boolean isFlush = Booleans.parseBoolean(immediateFlush, true);
   boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
   int reconnectDelay = AbstractAppender.parseInt(delay, 0);
   boolean fail = Booleans.parseBoolean(immediateFail, true);
   int port = AbstractAppender.parseInt(portNum, 0);
   boolean isAdvertise = Boolean.parseBoolean(advertise);
   Layout<? extends Serializable> layout =
       "RFC5424".equalsIgnoreCase(format)
           ? RFC5424Layout.createLayout(
               facility,
               id,
               ein,
               includeMDC,
               mdcId,
               mdcPrefix,
               eventPrefix,
               includeNL,
               escapeNL,
               appName,
               msgId,
               excludes,
               includes,
               required,
               exceptionPattern,
               "false",
               loggerFields,
               config)
           : SyslogLayout.createLayout(facility, includeNL, escapeNL, charsetName);
   if (name == null) {
     LOGGER.error("No name provided for SyslogAppender");
     return null;
   }
   Protocol p = (Protocol) EnglishEnums.valueOf(Protocol.class, protocol);
   AbstractSocketManager manager =
       createSocketManager(p, host, port, reconnectDelay, fail, layout);
   if (manager == null) {
     return null;
   }
   return new SyslogAppender(
       name,
       layout,
       filter,
       ignoreExceptions,
       isFlush,
       manager,
       isAdvertise ? config.getAdvertiser() : null);
 }