org.apache.logging.log4j.core.config.plugins.Plugin类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(449)

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

Plugin介绍

暂无

代码示例

代码示例来源:origin: apache/hive

/**
 * A log filter that filters test messages coming from the logger.
 */
@Plugin(name = "TestFilter", category = "Core", elementType="filter", printObject = true)
private static class TestFilter extends AbstractFilter {
 @Override
 public Result filter(LogEvent event) {
  if (event.getLevel().equals(Level.INFO) && "SessionState".equals(event.getLoggerName())) {
   if (event.getMessage().getFormattedMessage().startsWith("PREHOOK:")
     || event.getMessage().getFormattedMessage().startsWith("POSTHOOK:")
     || event.getMessage().getFormattedMessage().startsWith("unix_timestamp(void)")
     || event.getMessage().getFormattedMessage().startsWith("Warning: ")
     ) {
    return Result.ACCEPT;
   }
  }
  return Result.DENY;
 }
 @PluginFactory
 public static TestFilter createFilter() {
  return new TestFilter();
 }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testFakePluginFoundWithCorrectInformation() throws Exception {
  final PluginEntry fake = pluginCache.getCategory(p.category()).get(p.name().toLowerCase());
  verifyFakePluginEntry(p.name(), fake);
}

代码示例来源:origin: apache/hive

@Plugin(name = "PidFilePatternConverter", category = "FileConverter")
@ConverterKeys({ "pid" })
public class PidFilePatternConverter extends AbstractPatternConverter implements
  ArrayPatternConverter {

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
  public void testNestedPlugin() throws Exception {
    final Plugin p = FakePlugin.Nested.class.getAnnotation(Plugin.class);
    final PluginEntry nested = pluginCache.getCategory(p.category()).get(p.name().toLowerCase());
    assertNotNull(nested);
    assertEquals(p.name().toLowerCase(), nested.getKey());
    assertEquals(FakePlugin.Nested.class.getName(), nested.getClassName());
    assertEquals(p.name(), nested.getName());
    assertEquals(Plugin.EMPTY, p.elementType());
    assertEquals(p.printObject(), nested.isPrintable());
    assertEquals(p.deferChildren(), nested.isDefer());
  }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-catalog-api

default String getName() {
  Plugin annotation = this.getClass().getAnnotation(Plugin.class);
  if (annotation == null || annotation.name().length() == 0) {
    throw new NameNotFoundException("No name could be found for plugin class " + this.getClass().getName());
  }
  return annotation.name();
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testFakePluginAliasesContainSameInformation() throws Exception {
  final PluginAliases aliases = FakePlugin.class.getAnnotation(PluginAliases.class);
  for (final String alias : aliases.value()) {
    final PluginEntry fake = pluginCache.getCategory(p.category()).get(alias.toLowerCase());
    verifyFakePluginEntry(alias, fake);
  }
}

代码示例来源:origin: apache/geode

@Plugin(name = "HexThreadIdPatternConverter", category = "Converter")
@ConverterKeys({"hexTid", "hexThreadId"})
public class HexThreadIdPatternConverter extends LogEventPatternConverter {

代码示例来源:origin: ops4j/org.ops4j.pax.logging

@Override
  public PluginEntry visitType(final TypeElement e, final Plugin plugin) {
    Objects.requireNonNull(plugin, "Plugin annotation is null.");
    final PluginEntry entry = new PluginEntry();
    entry.setKey(plugin.name().toLowerCase(Locale.US));
    entry.setClassName(elements.getBinaryName(e).toString());
    entry.setName(Plugin.EMPTY.equals(plugin.elementType()) ? plugin.name() : plugin.elementType());
    entry.setPrintable(plugin.printObject());
    entry.setDefer(plugin.deferChildren());
    entry.setCategory(plugin.category());
    return entry;
  }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testTestCategoryFound() throws Exception {
  assertNotNull("No plugin annotation on FakePlugin.", p);
  final Map<String, PluginEntry> testCategory = pluginCache.getCategory(p.category());
  assertNotEquals("No plugins were found.", 0, pluginCache.size());
  assertNotNull("The category '" + p.category() + "' was not found.", testCategory);
  assertFalse(testCategory.isEmpty());
}

代码示例来源:origin: apache/hive

/**
 * A NullAppender merely exists, it never outputs a message to any device.
 */
@Plugin(name = "NullAppender", category = "Core", elementType = "appender", printObject = false)
public class NullAppender extends AbstractAppender {

 private static LoggerContext context = (LoggerContext) LogManager.getContext(false);
 private static Configuration configuration = context.getConfiguration();

 protected NullAppender(String name, Filter filter,
   Layout<? extends Serializable> layout, boolean ignoreExceptions) {
  super(name, filter, layout, ignoreExceptions);
 }

 @PluginFactory
 public static NullAppender createNullAppender() {
  return new NullAppender("NullAppender", null, PatternLayout.createDefaultLayout(), true);
 }

 public void addToLogger(String loggerName, Level level) {
  LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName);
  loggerConfig.addAppender(this, level, null);
  context.updateLoggers();
 }

 public void append(LogEvent event) {
  // no-op
 }
}

代码示例来源:origin: apache/drill

@Plugin(name = "PidFilePatternConverter", category = "FileConverter")
@ConverterKeys({ "pid" })
public class PidFilePatternConverter extends AbstractPatternConverter implements
  ArrayPatternConverter {

代码示例来源:origin: ops4j/org.ops4j.pax.logging

@Override
  public Collection<PluginEntry> visitType(final TypeElement e, final Plugin plugin) {
    final PluginAliases aliases = e.getAnnotation(PluginAliases.class);
    if (aliases == null) {
      return DEFAULT_VALUE;
    }
    final Collection<PluginEntry> entries = new ArrayList<>(aliases.value().length);
    for (final String alias : aliases.value()) {
      final PluginEntry entry = new PluginEntry();
      entry.setKey(alias.toLowerCase(Locale.US));
      entry.setClassName(elements.getBinaryName(e).toString());
      entry.setName(Plugin.EMPTY.equals(plugin.elementType()) ? alias : plugin.elementType());
      entry.setPrintable(plugin.printObject());
      entry.setDefer(plugin.deferChildren());
      entry.setCategory(plugin.category());
      entries.add(entry);
    }
    return entries;
  }
}

代码示例来源:origin: apache/drill

/**
 * A NullAppender merely exists, it never outputs a message to any device.
 */
@Plugin(name = "NullAppender", category = "Core", elementType = "appender", printObject = false)
public class NullAppender extends AbstractAppender {

 private static LoggerContext context = (LoggerContext) LogManager.getContext(false);
 private static Configuration configuration = context.getConfiguration();

 protected NullAppender(String name, Filter filter,
   Layout<? extends Serializable> layout, boolean ignoreExceptions) {
  super(name, filter, layout, ignoreExceptions);
 }

 @PluginFactory
 public static NullAppender createNullAppender() {
  return new NullAppender("NullAppender", null, PatternLayout.createDefaultLayout(), true);
 }

 public void addToLogger(String loggerName, Level level) {
  LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName);
  loggerConfig.addAppender(this, level, null);
  context.updateLoggers();
 }

 public void append(LogEvent event) {
  // no-op
 }
}

代码示例来源:origin: apache/geode

@Plugin(name = "MemberNamePatternConverter", category = "Converter")
@ConverterKeys("memberName")
public class MemberNamePatternConverter extends LogEventPatternConverter {

代码示例来源:origin: Graylog2/graylog2-server

@Plugin(name = "Memory", category = "Core", elementType = "appender", printObject = true)
public class MemoryAppender extends AbstractAppender {

代码示例来源:origin: org.springframework.boot/spring-boot

@Plugin(name = "WhitespaceThrowablePatternConverter", category = PatternConverter.CATEGORY)
@ConverterKeys({ "wEx", "wThrowable", "wException" })
public final class WhitespaceThrowablePatternConverter extends ThrowablePatternConverter {

代码示例来源:origin: apache/hive

@Plugin(name = "SlidingFilenameRolloverStrategy",
  category = "Core",
  printObject = true)

代码示例来源:origin: org.springframework.boot/spring-boot

@Plugin(name = "ExtendedWhitespaceThrowablePatternConverter", category = PatternConverter.CATEGORY)
@ConverterKeys({ "xwEx", "xwThrowable", "xwException" })
public final class ExtendedWhitespaceThrowablePatternConverter
    extends ThrowablePatternConverter {

代码示例来源:origin: apache/rocketmq

@Plugin(name = "RocketMQ",
  category = Node.CATEGORY,
  elementType = Appender.ELEMENT_TYPE,

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Plugin(name = "TestFormatPatternConverter", category = "Converter")
@ConverterKeys("testformat")
public static final class TestFormatPatternConverter extends LogEventPatternConverter {
  private TestFormatPatternConverter() {
    super("Format", "testformat");
  }
  public static TestFormatPatternConverter newInstance(final String[] options) {
    return new TestFormatPatternConverter();
  }
  @Override
  public void format(final LogEvent event, final StringBuilder toAppendTo) {
    toAppendTo.append(event.getMessage().getFormat());
  }
}

相关文章