use of org.apache.logging.log4j.core.config.plugins.PluginFactory in project hive by apache.
the class HushableRandomAccessFileAppender method createAppender.
// difference from standard File Appender:
// locking is not supported and buffering cannot be switched off
/**
* Create a File Appender.
*
* @param fileName The name and path of the file.
* @param append "True" if the file should be appended to, "false" if it
* should be overwritten. The default is "true".
* @param name The name of the Appender.
* @param immediateFlush "true" if the contents should be flushed on every
* write, "false" otherwise. The default is "true".
* @param bufferSizeStr The buffer size, defaults to {@value RandomAccessFileManager#DEFAULT_BUFFER_SIZE}.
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @param layout The layout to use to format the event. If no layout is
* provided the default PatternLayout will be used.
* @param filter The filter, if any, to use.
* @param advertise "true" if the appender configuration should be
* advertised, "false" otherwise.
* @param advertiseURI The advertised URI which can be used to retrieve the
* file contents.
* @param config The Configuration.
* @return The FileAppender.
*/
@PluginFactory
public static HushableRandomAccessFileAppender createAppender(@PluginAttribute("fileName") final String fileName, @PluginAttribute("append") final String append, @PluginAttribute("name") final String name, @PluginAttribute("immediateFlush") final String immediateFlush, @PluginAttribute("bufferSize") final String bufferSizeStr, @PluginAttribute("ignoreExceptions") final String ignore, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filter") final Filter filter, @PluginAttribute("advertise") final String advertise, @PluginAttribute("advertiseURI") final String advertiseURI, @PluginConfiguration final Configuration config) {
final boolean isAppend = Booleans.parseBoolean(append, true);
final boolean isFlush = Booleans.parseBoolean(immediateFlush, true);
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
final boolean isAdvertise = Boolean.parseBoolean(advertise);
final int bufferSize = Integers.parseInt(bufferSizeStr, 256 * 1024);
if (name == null) {
LOGGER.error("No name provided for FileAppender");
return null;
}
if (fileName == null) {
LOGGER.error("No filename provided for FileAppender with name " + name);
return null;
}
if (layout == null) {
layout = PatternLayout.createDefaultLayout();
}
final RandomAccessFileManager manager = RandomAccessFileManager.getFileManager(fileName, isAppend, isFlush, bufferSize, advertiseURI, layout, config);
if (manager == null) {
return null;
}
return new HushableRandomAccessFileAppender(name, layout, filter, manager, fileName, ignoreExceptions, isFlush, isAdvertise ? config.getAdvertiser() : null);
}
use of org.apache.logging.log4j.core.config.plugins.PluginFactory in project logging-log4j2 by apache.
the class TimeFilter method createFilter.
/**
* 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);
}
Aggregations