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

The following examples show how to use org.apache.logging.log4j.core.config.plugins.PluginFactory. 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: 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 #2
Source File: TimeFilter.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a TimeFilter.
 * @param start The start time.
 * @param end The end time.
 * @param tz timezone.
 * @param match Action to perform if the time matches.
 * @param mismatch Action to perform if the action does not match.
 * @return A TimeFilter.
 */
// TODO Consider refactoring to use AbstractFilter.AbstractFilterBuilder
@PluginFactory
public static TimeFilter createFilter(
        @PluginAttribute("start") final String start,
        @PluginAttribute("end") final String end,
        @PluginAttribute("timezone") final String tz,
        @PluginAttribute("onMatch") final Result match,
        @PluginAttribute("onMismatch") final Result mismatch) {
    final LocalTime startTime = parseTimestamp(start, LocalTime.MIN);
    final LocalTime endTime = parseTimestamp(end, LocalTime.MAX);
    final ZoneId timeZone = tz == null ? ZoneId.systemDefault() : ZoneId.of(tz);
    final Result onMatch = match == null ? Result.NEUTRAL : match;
    final Result onMismatch = mismatch == null ? Result.DENY : mismatch;
    return new TimeFilter(startTime, endTime, timeZone, onMatch, onMismatch);
}
 
Example #3
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 #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: 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 #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: 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 #8
Source File: CustomJsonLayout.java    From summerframework with Apache License 2.0 6 votes vote down vote up
@PluginFactory
public static CustomJsonLayout createLayout(@PluginConfiguration final Configuration config,
    @PluginAttribute(value = "locationInfo", defaultBoolean = false) final boolean locationInfo,
    @PluginAttribute(value = "properties", defaultBoolean = false) final boolean properties,
    @PluginAttribute(value = "propertiesAsList", defaultBoolean = false) final boolean propertiesAsList,
    @PluginAttribute(value = "complete", defaultBoolean = false) final boolean complete,
    @PluginAttribute(value = "compact", defaultBoolean = false) final boolean compact,
    @PluginAttribute(value = "eventEol", defaultBoolean = false) final boolean eventEol,
    @PluginAttribute(value = "header", defaultString = DEFAULT_HEADER) final String headerPattern,
    @PluginAttribute(value = "footer", defaultString = DEFAULT_FOOTER) final String footerPattern,
    @PluginAttribute(value = "charset", defaultString = "UTF-8") final Charset charset,
    @PluginAttribute(value = "includeStacktrace", defaultBoolean = true) final boolean includeStacktrace,
    @PluginAttribute(value = "stacktraceAsString", defaultBoolean = false) final boolean stacktraceAsString,
    @PluginAttribute(value = "objectMessageAsJsonObject",
        defaultBoolean = false) final boolean objectMessageAsJsonObject) {
    final boolean encodeThreadContextAsList = properties && propertiesAsList;
    return new CustomJsonLayout(config, locationInfo, properties, encodeThreadContextAsList, complete, compact,
        eventEol, headerPattern, footerPattern, charset, includeStacktrace, stacktraceAsString,
        objectMessageAsJsonObject);
}
 
Example #9
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 #10
Source File: GelfDynamicMdcLogFields.java    From xian with Apache License 2.0 5 votes vote down vote up
@PluginFactory
public static GelfDynamicMdcLogFields createField(@PluginConfiguration final Configuration config,
        @PluginAttribute("regex") String regex) {

    if (Strings.isEmpty(regex)) {
        LOGGER.error("The regex is empty");
        return null;
    }

    return new GelfDynamicMdcLogFields(regex);
}
 
Example #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
Source File: InstrumentedAppender.java    From client_java with Apache License 2.0 5 votes vote down vote up
@PluginFactory
public static InstrumentedAppender createAppender(
        @PluginAttribute("name") String name) {
    if (name == null) {
        LOGGER.error("No name provided for InstrumentedAppender");
        return null;
    }
    return new InstrumentedAppender(name);
}
 
Example #19
Source File: IbisXmlLayout.java    From iaf with Apache License 2.0 5 votes vote down vote up
@PluginFactory
public static IbisXmlLayout createLayout(
		@PluginConfiguration final Configuration config,
		// LOG4J2-783 use platform default by default, so do not specify defaultString for charset
		@PluginAttribute(value = "charset") final Charset charset,
		@PluginAttribute(value = "alwaysWriteExceptions", defaultBoolean = true) final boolean alwaysWriteExceptions) {
	return new IbisXmlLayout(config, charset, alwaysWriteExceptions);
}
 
Example #20
Source File: IbisPatternLayout.java    From iaf with Apache License 2.0 5 votes vote down vote up
@PluginFactory
public static IbisPatternLayout createLayout(
		@PluginAttribute(value = "pattern", defaultString = IbisPatternLayout.DEFAULT_PATTERN) final String pattern,
		@PluginConfiguration final Configuration config,
		// LOG4J2-783 use platform default by default, so do not specify defaultString for charset
		@PluginAttribute(value = "charset") final Charset charset,
		@PluginAttribute(value = "alwaysWriteExceptions", defaultBoolean = true) final boolean alwaysWriteExceptions,
		@PluginAttribute(value = "noConsoleNoAnsi") final boolean noConsoleNoAnsi,
		@PluginAttribute(value = "disableAnsi") final boolean disableAnsi) {
	return new IbisPatternLayout(config, pattern, charset, alwaysWriteExceptions, disableAnsi, noConsoleNoAnsi);
}
 
Example #21
Source File: IbisThreadFilter.java    From iaf with Apache License 2.0 5 votes vote down vote up
@PluginFactory
public static IbisThreadFilter createFilter(@PluginAttribute(value = "regex") String regex,
											@PluginAttribute(value = "level", defaultString = "WARN") Level level,
											@PluginAttribute(value = "onMatch", defaultString = "DENY") Result onMatch,
											@PluginAttribute(value = "onMismatch", defaultString = "NEUTRAL") Result onMismatch) {
	return new IbisThreadFilter(level, regex, onMatch, onMismatch);
}
 
Example #22
Source File: ThreadContextKeyExistsFilter.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
@PluginFactory
public static ThreadContextKeyExistsFilter createFilter(
    @PluginAttribute(value = "key") String key,
    @PluginAttribute(value = "acceptIfKeyExists") boolean acceptIfKeyExists,
    @PluginAttribute(value = "denyIfKeyDoesNotExist") boolean denyIfKeyDoesNotExist) {
    ThreadContextKeyExistsFilter filter = new ThreadContextKeyExistsFilter();
    filter.setKey(key);
    filter.setAcceptIfKeyExists(acceptIfKeyExists);
    filter.setDenyIfKeyDoesNotExist(denyIfKeyDoesNotExist);
    return filter;
}
 
Example #23
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 #24
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 #25
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 #26
Source File: Log4j1XmlLayout.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@PluginFactory
public static Log4j1XmlLayout createLayout(
        // @formatter:off
        @PluginAttribute(value = "locationInfo") final boolean locationInfo,
        @PluginAttribute(value = "properties") final boolean properties
        // @formatter:on
) {
    return new Log4j1XmlLayout(locationInfo, properties);
}
 
Example #27
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 #28
Source File: GelfLogField.java    From xian with Apache License 2.0 5 votes vote down vote up
@PluginFactory
public static GelfLogField createField(@PluginConfiguration final Configuration config,
        @PluginAttribute("name") String name, @PluginAttribute("literal") String literalValue,
        @PluginAttribute("mdc") String mdc, @PluginAttribute("pattern") String pattern) {

    final boolean isPattern = Strings.isNotEmpty(pattern);
    final boolean isLiteralValue = Strings.isNotEmpty(literalValue);
    final boolean isMDC = Strings.isNotEmpty(mdc);

    if (Strings.isEmpty(name)) {
        LOGGER.error("The name is empty");
        return null;
    }

    if ((isPattern && isLiteralValue) || (isPattern && isMDC) || (isLiteralValue && isMDC)) {
        LOGGER.error("The pattern, literal, and mdc attributes are mutually exclusive.");
        return null;
    }

    if (isPattern) {

        PatternLayout patternLayout = newBuilder().withPattern(pattern).withConfiguration(config)
                .withNoConsoleNoAnsi(false).withAlwaysWriteExceptions(false).build();

        return new GelfLogField(name, null, null, patternLayout);
    }

    return new GelfLogField(name, literalValue, mdc, null);
}
 
Example #29
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 #30
Source File: CustomMdcKeyElement.java    From cloudwatchlogs-java-appender with Apache License 2.0 5 votes vote down vote up
@PluginFactory
public static CustomMdcKeyElement createCustomMdcKey(@PluginAttribute("key") final String key) {
    if (Strings.isEmpty(key)) {
        LOGGER.error("customMdcKey needs a key and cannot be empty.");
        return null;
    }
    return new CustomMdcKeyElement(key);
}