org.apache.logging.log4j.core.config.plugins.PluginElement Java Examples

The following examples show how to use org.apache.logging.log4j.core.config.plugins.PluginElement. 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: UIAppender.java    From patchwork-patcher with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unused")
@PluginFactory
public static UIAppender createAppender(@PluginAttribute("name") String name, @PluginAttribute("maxLines") int maxLines,
			@PluginAttribute("ignoreExceptions") boolean ignoreExceptions,
			@PluginElement("Layout") Layout<?> layout, @PluginElement("Filters") Filter filter) {
	if (name == null) {
		LOGGER.error("No name provided for UIAppender");
		return null;
	}

	if (layout == null) {
		layout = JsonLayout.createDefaultLayout();
	}

	return new UIAppender(name, layout, filter, maxLines, ignoreExceptions);
}
 
Example #2
Source File: AllureLogAppender.java    From vividus with Apache License 2.0 6 votes vote down vote up
@PluginFactory
public static AllureLogAppender createAppender(@PluginAttribute("name") final String name,
        @PluginElement("Filter") Filter filter, @PluginElement("Layout") Layout<? extends Serializable> layout)
{
    if (name == null)
    {
        LOGGER.error("No name provided for AllureLogAppender");
        instance = null;
    }
    else
    {
        instance = new AllureLogAppender(name, filter, layout);
    }

    return instance;
}
 
Example #3
Source File: ConsoleAppender.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a Console Appender.
 * @param layout The layout to use (required).
 * @param filter The Filter or null.
 * @param t The target ("SYSTEM_OUT" or "SYSTEM_ERR"). The default is "SYSTEM_OUT".
 * @param follow If true will follow changes to the underlying output stream.
 * @param name The name of the Appender (required).
 * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
 *               they are propagated to the caller.
 * @return The ConsoleAppender.
 */
@PluginFactory
public static ConsoleAppender createAppender(
        @PluginElement("Layout") Layout<? extends Serializable> layout,
        @PluginElement("Filters") final Filter filter,
        @PluginAttribute("target") final String t,
        @PluginAttribute("name") final String name,
        @PluginAttribute("follow") final String follow,
        @PluginAttribute("ignoreExceptions") final String ignore) {
    if (name == null) {
        LOGGER.error("No name provided for ConsoleAppender");
        return null;
    }
    if (layout == null) {
        layout = PatternLayout.createLayout(null, null, null, null, null);
    }
    final boolean isFollow = Boolean.parseBoolean(follow);
    final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
    final Target target = t == null ? Target.SYSTEM_OUT : Target.valueOf(t);
    return new ConsoleAppender(name, layout, filter, getManager(isFollow, target, layout), ignoreExceptions);
}
 
Example #4
Source File: JesterJAppender.java    From jesterj with Apache License 2.0 6 votes vote down vote up
@PluginFactory
public static JesterJAppender createAppender(@PluginAttribute("name") String name,
                                             @PluginAttribute("ignoreExceptions") boolean ignoreExceptions,
                                             @PluginElement("Layout") Layout layout,
                                             @PluginElement("Filters") Filter filter) {

  if (name == null) {
    LOGGER.error("No name provided for JesterJAppender");
    return null;
  }

  manager = createManager();
  if (manager == null) {
    return null; // should never happen
  }
  if (layout == null) {
    layout = PatternLayout.createDefaultLayout();
  }
  cassandra.addStatement(FTI_INSERT_Q, INSERT_FTI);
  cassandra.addStatement(REG_INSERT_Q, INSERT_REG);
  return new JesterJAppender(name, layout, filter, manager, ignoreExceptions);
}
 
Example #5
Source File: SpectatorAppender.java    From spectator with Apache License 2.0 6 votes vote down vote up
/** Create a new instance of the appender using the global spectator registry. */
@PluginFactory
public static SpectatorAppender createAppender(
    @PluginAttribute("name") String name,
    @PluginAttribute("ignoreExceptions") boolean ignoreExceptions,
    @PluginElement("Layout") Layout<? extends Serializable> layout,
    @PluginElement("Filters") Filter filter) {

  if (name == null) {
    LOGGER.error("no name provided for SpectatorAppender");
    return null;
  }

  return new SpectatorAppender(
      Spectator.globalRegistry(),
      name, filter, layout, ignoreExceptions,
      Property.EMPTY_ARRAY);
}
 
Example #6
Source File: InMemoryAppenderImpl.java    From GreenSummer with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates the appender.
 *
 * @param name the name
 * @param layout the layout
 * @param filter the filter
 * @param size the size
 * @return the in memory appender impl
 */
// the configured attributes.
@PluginFactory
public static InMemoryAppenderImpl createAppender(@PluginAttribute("name") String name,
    @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filter")
    final Filter filter, @PluginAttribute("size") int size) {
    Layout<? extends Serializable> layoutAux = layout;
    if (name == null) {
        LOGGER.error("No name provided for InMemoryAppenderImpl");
        return null;
    }
    if (layoutAux == null) {
        layoutAux = PatternLayout.createDefaultLayout();
    }
    return new InMemoryAppenderImpl(name, filter, layoutAux, true, size);
}
 
Example #7
Source File: CircularQueueLogAppender.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
@PluginFactory
public static CircularQueueLogAppender createAppender(
    @PluginAttribute(value = "name") String name,
    @PluginElement(value = "Filters") Filter filter,
    @PluginElement(value = "Layout") Layout<? extends Serializable> layout,
    @PluginAttribute(value = "ignoreExceptions") boolean ignoreExceptions,
    @PluginAttribute(value = "maxQueueSize") int maxQueueSize,
    @PluginAttribute(value = "dateFormat") String dateFormat,
    @PluginAttribute(value = "global") boolean global) {

    if (StringUtils.isEmpty(name)) {
        LOGGER.error("No name provided for " + PLUGIN_NAME);
        return null;
    }

    if (Objects.isNull(layout)) {
        layout = PatternLayout.createDefaultLayout();
    }

    if (Objects.isNull(buffer)) {
        LOGGER.debug("Initializing circular log queue buffer");
        if (maxQueueSize <= 0) {
            throw new IllegalArgumentException("maxQueueSize must be a integer bigger that 0");
        }
        buffer = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(maxQueueSize));
    }

    CircularQueueLogAppender appender = new CircularQueueLogAppender(name, filter, layout, ignoreExceptions, null);
    appender.dateFormat = DateTimeFormatter.ofPattern(dateFormat).withZone(ZoneId.of("UTC"));
    appender.global = global;

    return appender;
}
 
Example #8
Source File: SystemdJournalAppender.java    From log4j-systemd-journal-appender with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@PluginFactory
public static SystemdJournalAppender createAppender(@PluginAttribute("name") final String name,
        @PluginAttribute("ignoreExceptions") final String ignoreExceptionsString,
        @PluginAttribute("logSource") final String logSourceString,
        @PluginAttribute("logStacktrace") final String logStacktraceString,
        @PluginAttribute("logLoggerName") final String logLoggerNameString,
        @PluginAttribute("logAppenderName") final String logAppenderNameString,
        @PluginAttribute("logThreadName") final String logThreadNameString,
        @PluginAttribute("logThreadContext") final String logThreadContextString,
        @PluginAttribute("threadContextPrefix") final String threadContextPrefix,
        @PluginAttribute("syslogIdentifier") final String syslogIdentifier,
        @PluginAttribute("syslogFacility") final String syslogFacility,
        @PluginElement("Layout") final Layout<?> layout,
        @PluginElement("Filter") final Filter filter,
        @PluginConfiguration final Configuration config) {
    final boolean ignoreExceptions = Booleans.parseBoolean(ignoreExceptionsString, true);
    final boolean logSource = Booleans.parseBoolean(logSourceString, false);
    final boolean logStacktrace = Booleans.parseBoolean(logStacktraceString, true);
    final boolean logThreadName = Booleans.parseBoolean(logThreadNameString, true);
    final boolean logLoggerName = Booleans.parseBoolean(logLoggerNameString, true);
    final boolean logAppenderName = Booleans.parseBoolean(logAppenderNameString, true);
    final boolean logThreadContext = Booleans.parseBoolean(logThreadContextString, true);

    if (name == null) {
        LOGGER.error("No name provided for SystemdJournalAppender");
        return null;
    }

    final SystemdJournalLibrary journalLibrary;
    try {
        journalLibrary = Native.loadLibrary("systemd", SystemdJournalLibrary.class);
    } catch (UnsatisfiedLinkError e) {
        throw new RuntimeException("Failed to load systemd library." +
            " Please note that JNA requires an executable temporary folder." +
            " It can be explicitly defined with -Djna.tmpdir", e);
    }

    return new SystemdJournalAppender(name, filter, layout, ignoreExceptions, journalLibrary, logSource, logStacktrace,
            logThreadName, logLoggerName, logAppenderName, logThreadContext, threadContextPrefix, syslogIdentifier, syslogFacility);
}
 
Example #9
Source File: StringBuilderAppender.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Factory method. Log4j will parse the configuration and call this factory 
 * method to construct the appender with
 * the configured attributes.
 *
 * @param name   Name of appender
 * @param layout Log layout of appender
 * @param filter Filter for appender
 * @return The TextAreaAppender
 */
@PluginFactory
public static StringBuilderAppender createAppender(
    @PluginAttribute("name") String name,
    @PluginElement("Layout") Layout<? extends Serializable> layout,
    @PluginElement("Filter") final Filter filter) {
  if (name == null) {
    LOGGER.error("No name provided for TextAreaAppender2");
    return null;
  }
  if (layout == null) {
    layout = PatternLayout.createDefaultLayout();
  }
  return new StringBuilderAppender(name, filter, layout, true);
}
 
Example #10
Source File: ConsoleAppender.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Factory method. Log4j will parse the configuration and call this factory 
 * method to construct the appender with
 * the configured attributes.
 *
 * @param name   Name of appender
 * @param layout Log layout of appender
 * @param filter Filter for appender
 * @return The TextAreaAppender
 */
@PluginFactory
public static ConsoleAppender createAppender(
    @PluginAttribute("name") String name,
    @PluginElement("Layout") Layout<? extends Serializable> layout,
    @PluginElement("Filter") final Filter filter) {
  if (name == null) {
    LOGGER.error("No name provided for TextAreaAppender2");
    return null;
  }
  if (layout == null) {
    layout = PatternLayout.createDefaultLayout();
  }
  return new ConsoleAppender(name, filter, layout, true);
}
 
Example #11
Source File: TextAreaAppender.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Factory method. Log4j will parse the configuration and call this factory 
 * method to construct the appender with
 * the configured attributes.
 *
 * @param name   Name of appender
 * @param layout Log layout of appender
 * @param filter Filter for appender
 * @return The TextAreaAppender
 */
@PluginFactory
public static TextAreaAppender createAppender(
    @PluginAttribute("name") String name,
    @PluginElement("Layout") Layout<? extends Serializable> layout,
    @PluginElement("Filter") final Filter filter) {
  if (name == null) {
    LOGGER.error("No name provided for TextAreaAppender2");
    return null;
  }
  if (layout == null) {
    layout = PatternLayout.createDefaultLayout();
  }
  return new TextAreaAppender(name, filter, layout, true);
}
 
Example #12
Source File: StructuredJsonLayoutPlugin.java    From common with Apache License 2.0 5 votes vote down vote up
@PluginFactory
public static StructuredLayout createLayout(
    @PluginElement("Properties") final Property[] properties) {
  final JsonConverter converter = new JsonConverter();
  converter.configure(
      Arrays.stream(properties).collect(
          Collectors.toMap(Property::getName, Property::getValue)
      ),
      false
  );
  return new StructuredLayout(struct -> converter.fromConnectData("", struct.schema(), struct));
}
 
Example #13
Source File: MemoryAppender.java    From syncope with Apache License 2.0 5 votes vote down vote up
@PluginFactory
public static MemoryAppender createAppender(
        @PluginAttribute("name") final String name,
        @PluginAttribute(value = "size", defaultInt = 10) final int size,
        @PluginElement("Filter") final Filter filter,
        @PluginAttribute(value = "ignoreExceptions", defaultBoolean = true) final boolean ignoreExceptions) {

    return new MemoryAppender(
            name,
            size,
            filter,
            ignoreExceptions);
}
 
Example #14
Source File: JSwingAppender.java    From collect-earth with MIT License 5 votes vote down vote up
@PluginFactory
public static JSwingAppender createAppender(@PluginAttribute("name") String name,
		@PluginElement("Layout") Layout<?> layout, @PluginElement("Filters") Filter filter,
		@PluginAttribute("ignoreExceptions") boolean ignoreExceptions) {

	if (name == null) {
		LoggerFactory.getLogger( JSwingAppender.class ).error("No name provided for JTextAreaAppender");
		return null;
	}

	if (layout == null) {
		layout = PatternLayout.createDefaultLayout();
	}
	return new JSwingAppender(name, filter, layout, ignoreExceptions);
}
 
Example #15
Source File: RollbarAppender.java    From rollbar-java with MIT License 5 votes vote down vote up
/**
 * Create appender plugin factory method.
 *
 * @param accessToken the Rollbar access token.
 * @param codeVersion the codeVersion.
 * @param endpoint the Rollbar endpoint to be used.
 * @param environment the environment.
 * @param language the language.
 * @param enabled to enable or disable Rollbar.
 * @param configProviderClassName The class name of the config provider implementation to get
 *     the configuration.
 * @param name the name.
 * @param layout the layout.
 * @param filter the filter.
 * @param ignore the ignore exceptions flag.
 * @return the rollbar appender.
 */
@PluginFactory
public static RollbarAppender createAppender(
    @PluginAttribute("accessToken") @Required final String accessToken,
    @PluginAttribute("codeVersion") final String codeVersion,
    @PluginAttribute("endpoint") final String endpoint,
    @PluginAttribute("environment") final String environment,
    @PluginAttribute("language") final String language,
    @PluginAttribute("enabled") final boolean enabled,
    @PluginAttribute("configProviderClassName") final String configProviderClassName,
    @PluginAttribute("name") @Required final String name,
    @PluginElement("Layout") Layout<? extends Serializable> layout,
    @PluginElement("Filter") Filter filter,
    @PluginAttribute("ignoreExceptions") final String ignore
) {

  ConfigProvider configProvider = ConfigProviderHelper
      .getConfigProvider(configProviderClassName);
  Config config;

  ConfigBuilder configBuilder = withAccessToken(accessToken)
      .codeVersion(codeVersion)
      .environment(environment)
      .endpoint(endpoint)
      .server(new ServerProvider())
      .language(language)
      .enabled(enabled);

  if (configProvider != null) {
    config = configProvider.provide(configBuilder);
  } else {
    config = configBuilder.build();
  }

  Rollbar rollbar = new Rollbar(config);

  boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);

  return new RollbarAppender(name, filter, layout, ignoreExceptions, rollbar);
}
 
Example #16
Source File: Log4J2DialogAppender.java    From consulo with Apache License 2.0 5 votes vote down vote up
@PluginFactory
public static Log4J2DialogAppender createAppender(@PluginAttribute("name") String name,
                                                  @PluginElement("Layout") Layout<? extends Serializable> layout,
                                                  @PluginElement("Filter") final Filter filter) {
  if (name == null) {
    LOGGER.error("No name provided for Log4J2DialogAppender");
    return null;
  }
  if (layout == null) {
    layout = PatternLayout.createDefaultLayout();
  }
  return new Log4J2DialogAppender(name, filter, layout);
}
 
Example #17
Source File: StreamAppender.java    From samza with Apache License 2.0 5 votes vote down vote up
@PluginFactory
public static StreamAppender createAppender(
    @PluginAttribute("name") final String name,
    @PluginElement("Filter") final Filter filter,
    @PluginElement("Layout") Layout layout,
    @PluginAttribute(value = "ignoreExceptions", defaultBoolean = true) final boolean ignoreExceptions,
    @PluginAttribute("streamName") String streamName) {
  return new StreamAppender(name, filter, layout, ignoreExceptions, streamName);
}
 
Example #18
Source File: MockSystemProducerAppender.java    From samza with Apache License 2.0 5 votes vote down vote up
@PluginFactory
public static MockSystemProducerAppender createAppender(
    @PluginAttribute("name") final String name,
    @PluginElement("Filter") final Filter filter,
    @PluginElement("Layout") Layout<? extends Serializable> layout,
    @PluginAttribute(value = "ignoreExceptions", defaultBoolean = true) final boolean ignoreExceptions,
    @PluginElement("Config") final Config testConfig,
    @PluginAttribute("streamName") String streamName) {
  if (testConfig == null) {
    initConfig();
  } else {
    config = testConfig;
  }
  return new MockSystemProducerAppender(name, filter, layout, ignoreExceptions, config, streamName);
}
 
Example #19
Source File: TextAreaAppender.java    From ModPackDownloader with MIT License 5 votes vote down vote up
/**
 * Factory method. Log4j will parse the configuration and call this factory
 * method to construct the appender with
 * the configured attributes.
 *
 * @param name   Name of appender
 * @param layout Log layout of appender
 * @param filter Filter for appender
 * @return The TextAreaAppender
 */
@PluginFactory
public static TextAreaAppender createAppender(
		@PluginAttribute("name") String name,
		@PluginElement("Layout") Layout<? extends Serializable> layout,
		@PluginElement("Filter") final Filter filter) {
	if (name == null) {
		LOGGER.error("No name provided for TextAreaAppender");
		return null;
	}
	if (layout == null) {
		layout = PatternLayout.createDefaultLayout();
	}
	return new TextAreaAppender(name, filter, layout, true);
}
 
Example #20
Source File: TerminalConsoleAppender.java    From TerminalConsoleAppender with MIT License 5 votes vote down vote up
/**
 * Creates a new {@link TerminalConsoleAppender}.
 *
 * @param name The name of the appender
 * @param filter The filter, can be {@code null}
 * @param layout The layout, can be {@code null}
 * @param ignoreExceptions If {@code true} exceptions encountered when
 *     appending events are logged, otherwise they are propagated to the
 *     caller
 * @return The new appender
 */
@PluginFactory
public static TerminalConsoleAppender createAppender(
        @Required(message = "No name provided for TerminalConsoleAppender") @PluginAttribute("name") String name,
        @PluginElement("Filter") Filter filter,
        @PluginElement("Layout") @Nullable Layout<? extends Serializable> layout,
        @PluginAttribute(value = "ignoreExceptions", defaultBoolean = true) boolean ignoreExceptions) {

    if (layout == null) {
        layout = PatternLayout.createDefaultLayout();
    }

    return new TerminalConsoleAppender(name, filter, layout, ignoreExceptions);
}
 
Example #21
Source File: AdvancedKafkaAppender.java    From summerframework with Apache License 2.0 5 votes vote down vote up
@PluginFactory
public static AdvancedKafkaAppender createAppender(
    @PluginElement("Layout") final Layout<? extends Serializable> layout,
    @PluginElement("Filter") final Filter filter, //
    @PluginConfiguration final Configuration configuration,
    @Required(message = "No name provided for KafkaAppender") @PluginAttribute("name") final String name,
    @Required(message = "No topic provided for KafkaAppender") @PluginAttribute("topic") final String topic,
    @Required(
        message = "No bootstrapServers provided for KafkaAppender") @PluginAttribute("bootstrapServers") final String bootstrapServers) {
    final AdvancedKafkaManager advancedKafkaManager =
        new AdvancedKafkaManager(configuration.getLoggerContext(), name, bootstrapServers);
    return new AdvancedKafkaAppender(name, layout, filter, false, advancedKafkaManager, topic);
}
 
Example #22
Source File: FrontConsoleAppender.java    From molicode with Apache License 2.0 5 votes vote down vote up
@PluginFactory
public static FrontConsoleAppender createAppender(@PluginAttribute("name") String name,
                                                  @PluginAttribute("fileName") String fileName,
                                                  @PluginElement("Filter") final Filter filter,
                                                  @PluginElement("Layout") Layout<? extends Serializable> layout,
                                                  @PluginAttribute("ignoreExceptions") boolean ignoreExceptions) {
    if (name == null) {
        LOGGER.error("no name defined in conf.");
        return null;
    }
    if (layout == null) {
        layout = PatternLayout.createDefaultLayout();
    }
    return new FrontConsoleAppender(name, filter, layout, ignoreExceptions, fileName);
}
 
Example #23
Source File: CatAppender4Log4j2.java    From x-pipe with Apache License 2.0 4 votes vote down vote up
@PluginFactory
public static CatAppender4Log4j2 createAppender(@PluginAttribute("name") String name,
		@PluginElement("Layout") Layout<? extends Serializable> layout,
		@PluginElement("Filter") final Filter filter) {
	return new CatAppender4Log4j2(name, filter, layout);
}
 
Example #24
Source File: JsonPatternLayout.java    From cf-java-logging-support with Apache License 2.0 4 votes vote down vote up
@PluginFactory
public static JsonPatternLayout createLayout(@PluginAttribute(value = "charset") final Charset charset,
		@PluginElement(value = "customField") CustomField[] customFieldMdcKeyNames,
		@PluginConfiguration final Configuration config) {
	return new JsonPatternLayout(config, charset, customFieldMdcKeyNames);
}
 
Example #25
Source File: CloudwatchLogsLog4J2Appender.java    From cloudwatchlogs-java-appender with Apache License 2.0 4 votes vote down vote up
@PluginFactory
public static CloudwatchLogsLog4J2Appender createAppender(
        @PluginAttribute(value = "name", defaultString = APPENDER_NAME) String name,
        @PluginElement("Filter") final Filter filter,
        @PluginElement("customMdcKey") final CustomMdcKeyElement[] customMdcKeys,
        @PluginAttribute("debug") Boolean debug,
        @PluginAttribute("stdoutFallback") Boolean stdoutFallback,
        @PluginAttribute("endpoint") String endpoint,
        @PluginAttribute("env") String env,
        @PluginAttribute("image") String image,
        @PluginAttribute("instance") String instance,
        @PluginAttribute(value = "maxEventQueueSize", defaultInt = CloudwatchLogsConfig.DEFAULT_MAX_EVENT_QUEUE_SIZE) Integer maxEventQueueSize,
        @PluginAttribute(value = "maxFlushDelay", defaultLong = CloudwatchLogsConfig.DEFAULT_MAX_FLUSH_DELAY) Long maxFlushDelay,
        @PluginAttribute("region") String region,
        @PluginAttribute("logGroup") String logGroup) {
    CloudwatchLogsLog4J2Appender appender = new CloudwatchLogsLog4J2Appender(name, filter, null, true);
    if (debug != null) {
        appender.getConfig().setStdoutFallback(debug);
    }
    if (stdoutFallback != null) {
        appender.getConfig().setStdoutFallback(stdoutFallback);
    }
    if (endpoint != null) {
        appender.getConfig().setEndpoint(endpoint);
    }
    if (env != null) {
        appender.getConfig().setEnv(env);
    }
    if (image != null) {
        appender.getConfig().setImage(image);
    }
    if (instance != null) {
        appender.getConfig().setInstance(instance);
    }
    appender.getConfig().setMaxEventQueueSize(maxEventQueueSize);
    appender.getConfig().setMaxFlushDelay(maxFlushDelay);
    if (region != null) {
        appender.getConfig().setRegion(region);
    }
    if (logGroup != null) {
        appender.getConfig().setLogGroup(logGroup);
    }
    for (CustomMdcKeyElement customMdcKey : customMdcKeys) {
        appender.getConfig().addCustomMdcKey(customMdcKey.getKey());
    }
    return appender;
}
 
Example #26
Source File: CatLog4j2ErrorAppender.java    From hermes with Apache License 2.0 4 votes vote down vote up
@PluginFactory
public static CatLog4j2ErrorAppender createAppender(@PluginAttribute("name") String name,
      @PluginElement("Filter") final Filter filter, @PluginElement("Layout") Layout<? extends Serializable> layout,
      @PluginAttribute("ignoreExceptions") boolean ignoreExceptions) {
	return new CatLog4j2ErrorAppender(name, filter, layout, ignoreExceptions);
}
 
Example #27
Source File: LoghubAppender.java    From aliyun-log-log4j2-appender with Apache License 2.0 4 votes vote down vote up
@PluginFactory
public static LoghubAppender createAppender(
        @PluginAttribute("name") final String name,
        @PluginElement("Filter") final Filter filter,
        @PluginElement("Layout") Layout<? extends Serializable> layout,
        @PluginConfiguration final Configuration config,
        @PluginAttribute("ignoreExceptions") final String ignore,
        @PluginAttribute("project") final String project,
        @PluginAttribute("logStore") final String logStore,
        @PluginAttribute("endpoint") final String endpoint,
        @PluginAttribute("accessKeyId") final String accessKeyId,
        @PluginAttribute("accessKeySecret") final String accessKeySecret,
        @PluginAttribute("stsToken") final String stsToken,

        @PluginAttribute("totalSizeInBytes") final String  totalSizeInBytes,
        @PluginAttribute("maxBlockMs") final String  maxBlockMs,
        @PluginAttribute("ioThreadCount") final String  ioThreadCount,
        @PluginAttribute("batchSizeThresholdInBytes") final String  batchSizeThresholdInBytes,
        @PluginAttribute("batchCountThreshold") final String  batchCountThreshold,
        @PluginAttribute("lingerMs") final String  lingerMs,
        @PluginAttribute("retries") final String  retries,
        @PluginAttribute("baseRetryBackoffMs") final String  baseRetryBackoffMs,
        @PluginAttribute("maxRetryBackoffMs") final String maxRetryBackoffMs,

        @PluginAttribute("topic") final String topic,
        @PluginAttribute("source") final String source,
        @PluginAttribute("timeFormat") final String timeFormat,
        @PluginAttribute("timeZone") final String timeZone,
        @PluginAttribute("mdcFields") final String mdcFields) {

    Boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);

    int maxBlockMsInt = parseStrToInt(maxBlockMs, 60);

    int baseRetryBackoffMsInt = parseStrToInt(baseRetryBackoffMs, 100);

    int maxRetryBackoffMsInt = parseStrToInt(maxRetryBackoffMs, 100);

    int lingerMsInt = parseStrToInt(lingerMs, 3000);

    int batchCountThresholdInt = parseStrToInt(batchCountThreshold, 4096);

    int batchSizeThresholdInBytesInt = parseStrToInt(batchSizeThresholdInBytes, 5 * 1024 * 1024);

    int totalSizeInBytesInt = parseStrToInt(totalSizeInBytes, 104857600);

    int retriesInt = parseStrToInt(retries, 3);

    int ioThreadCountInt = parseStrToInt(ioThreadCount, 8);

    String pattern = isStrEmpty(timeFormat) ? DEFAULT_TIME_FORMAT : timeFormat;
    String timeZoneInfo = isStrEmpty(timeZone) ? DEFAULT_TIME_ZONE : timeZone;
    DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern).withZone(DateTimeZone.forID(timeZoneInfo));

    return new LoghubAppender(name, filter, layout, ignoreExceptions, project, logStore, endpoint,
            accessKeyId, accessKeySecret, stsToken,totalSizeInBytesInt,maxBlockMsInt,ioThreadCountInt,
            batchSizeThresholdInBytesInt,batchCountThresholdInt,lingerMsInt,retriesInt,
            baseRetryBackoffMsInt, maxRetryBackoffMsInt,topic, source, formatter,mdcFields);
}
 
Example #28
Source File: Log4j2QiniuAppender.java    From qiniu-logging-plugin with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * create the qiniu logdb appender
 *
 * @param name              name
 * @param workflowName      pandora workflow name
 * @param pipelineRepo      pandora pipeline repo name
 * @param logdbRepo         pandora logdb repo name
 * @param autoFlushInterval auto flush log interval in seconds
 * @param accessKey         qiniu access key
 * @param secretKey         qiniu secret key
 * @param filter            filter
 * @param layout            layout
 * @param ignoreExceptions  ignoreExceptions
 */
@PluginFactory
public static Log4j2QiniuAppender createAppender(@PluginAttribute("name") String name,
                                                 @PluginAttribute("pipelineHost") String pipelineHost,
                                                 @PluginAttribute("logdbHost") String logdbHost,
                                                 @PluginAttribute("workflowName") String workflowName,
                                                 @PluginAttribute("workflowDesc") String workflowDesc,
                                                 @PluginAttribute("workflowRegion") String workflowRegion,
                                                 @PluginAttribute("pipelineRepo") String pipelineRepo,
                                                 @PluginAttribute("logdbRepo") String logdbRepo,
                                                 @PluginAttribute("logdbRetention") String logdbRetention,
                                                 @PluginAttribute("accessKey") String accessKey,
                                                 @PluginAttribute("secretKey") String secretKey,
                                                 @PluginAttribute("autoFlushInterval") int autoFlushInterval,
                                                 @PluginAttribute("logCacheDir") String logCacheDir,
                                                 @PluginAttribute("logRotateInterval") int logRotateInterval,
                                                 @PluginAttribute("logRetryInterval") int logRetryInterval,
                                                 @PluginAttribute("logPushThreadPoolSize") int logPushThreadPoolSize,
                                                 @PluginAttribute("logPushConnectTimeout") int logPushConnectTimeout,
                                                 @PluginAttribute("logPushReadTimeout") int logPushReadTimeout,
                                                 @PluginAttribute("logPushWriteTimeout") int logPushWriteTimeout,
                                                 @PluginAttribute("logRetryThreadPoolSize") int logRetryThreadPoolSize,
                                                 @PluginAttribute("logRetryConnectTimeout") int logRetryConnectTimeout,
                                                 @PluginAttribute("logRetryReadTimeout") int logRetryReadTimeout,
                                                 @PluginAttribute("logRetryWriteTimeout") int logRetryWriteTimeout,
                                                 @PluginElement("filter") final Filter filter,
                                                 @PluginElement("layout") Layout<? extends Serializable> layout,
                                                 @PluginAttribute("ignoreExceptions") boolean ignoreExceptions) {

    Auth auth = Auth.create(accessKey, secretKey);
    PandoraClient client = new PandoraClientImpl(auth);

    //check attributes
    if (workflowRegion == null || workflowRegion.isEmpty()) {
        workflowRegion = DefaultWorkflowRegion;
    }
    if (logdbRetention == null || logdbRetention.isEmpty()) {
        logdbRetention = DefaultLogdbRetention;
    }

    //try to create appender workflow
    try {
        QiniuAppenderClient.createAppenderWorkflow(client, pipelineHost, logdbHost, workflowName, workflowDesc,
                workflowRegion, pipelineRepo, logdbRepo, logdbRetention);
    } catch (Exception e) {
        e.printStackTrace();
        return null;//logging appender initialization failed
    }

    return new Log4j2QiniuAppender(name, filter, layout, ignoreExceptions, auth, pipelineHost, pipelineRepo,
            autoFlushInterval, logCacheDir, logRotateInterval, logRetryInterval, logPushThreadPoolSize,
            logPushConnectTimeout, logPushReadTimeout, logPushWriteTimeout, logRetryThreadPoolSize,
            logRetryConnectTimeout, logRetryReadTimeout, logRetryWriteTimeout);
}
 
Example #29
Source File: MapAppender.java    From tutorials with MIT License 4 votes vote down vote up
@PluginFactory
public static MapAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Filter") final Filter filter) {
    return new MapAppender(name, filter);
}
 
Example #30
Source File: ListAppender.java    From tutorials with MIT License 4 votes vote down vote up
@PluginFactory
public static ListAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Filter") final Filter filter) {
    return new ListAppender(name, filter);
}