Search in sources :

Example 11 with PluginFactory

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);
}
Also used : RandomAccessFileManager(org.apache.logging.log4j.core.appender.RandomAccessFileManager) PluginFactory(org.apache.logging.log4j.core.config.plugins.PluginFactory)

Example 12 with PluginFactory

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);
}
Also used : LocalTime(java.time.LocalTime) ZoneId(java.time.ZoneId) PluginFactory(org.apache.logging.log4j.core.config.plugins.PluginFactory)

Aggregations

PluginFactory (org.apache.logging.log4j.core.config.plugins.PluginFactory)12 Method (java.lang.reflect.Method)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DataSource (javax.sql.DataSource)2 DB (com.mongodb.DB)1 MongoClient (com.mongodb.MongoClient)1 ServerAddress (com.mongodb.ServerAddress)1 WriteConcern (com.mongodb.WriteConcern)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1 URI (java.net.URI)1 Charset (java.nio.charset.Charset)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1