Search in sources :

Example 1 with RandomAccessFileManager

use of org.apache.logging.log4j.core.appender.RandomAccessFileManager 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)

Aggregations

RandomAccessFileManager (org.apache.logging.log4j.core.appender.RandomAccessFileManager)1 PluginFactory (org.apache.logging.log4j.core.config.plugins.PluginFactory)1