/** * Create a RollingRandomAccessFileAppender. * * @param fileName The name of the file that is actively written to. (required). * @param filePattern The pattern of the file name to use on rollover. (required). * @param append If true, events are appended to the file. If false, the file is overwritten when * opened. Defaults to "true" * @param name The name of the Appender (required). * @param immediateFlush When true, events are immediately flushed. Defaults to "true". * @param bufferSizeStr The buffer size, defaults to {@value * RollingRandomAccessFileManager#DEFAULT_BUFFER_SIZE}. * @param policy The triggering policy. (required). * @param strategy The rollover strategy. Defaults to DefaultRolloverStrategy. * @param layout The layout to use (defaults to the default PatternLayout). * @param filter The Filter or null. * @param ignore If {@code "true"} (default) exceptions encountered when appending events are * logged; otherwise they are propagated to the caller. * @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 A RollingRandomAccessFileAppender. */ @PluginFactory public static RollingRandomAccessFileAppender createAppender( @PluginAttribute("fileName") final String fileName, @PluginAttribute("filePattern") final String filePattern, @PluginAttribute("append") final String append, @PluginAttribute("name") final String name, @PluginAttribute("immediateFlush") final String immediateFlush, @PluginAttribute("bufferSize") final String bufferSizeStr, @PluginElement("Policy") final TriggeringPolicy policy, @PluginElement("Strategy") RolloverStrategy strategy, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filter") final Filter filter, @PluginAttribute("ignoreExceptions") final String ignore, @PluginAttribute("advertise") final String advertise, @PluginAttribute("advertiseURI") final String advertiseURI, @PluginConfiguration final Configuration config) { final boolean isAppend = Booleans.parseBoolean(append, true); final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true); final boolean isFlush = Booleans.parseBoolean(immediateFlush, true); final boolean isAdvertise = Boolean.parseBoolean(advertise); final int bufferSize = Integers.parseInt(bufferSizeStr, RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE); if (name == null) { LOGGER.error("No name provided for FileAppender"); return null; } if (fileName == null) { LOGGER.error("No filename was provided for FileAppender with name " + name); return null; } if (filePattern == null) { LOGGER.error("No filename pattern provided for FileAppender with name " + name); return null; } if (policy == null) { LOGGER.error("A TriggeringPolicy must be provided"); return null; } if (strategy == null) { strategy = DefaultRolloverStrategy.createStrategy( null, null, null, String.valueOf(Deflater.DEFAULT_COMPRESSION), config); } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } final RollingRandomAccessFileManager manager = RollingRandomAccessFileManager.getRollingRandomAccessFileManager( fileName, filePattern, isAppend, isFlush, bufferSize, policy, strategy, advertiseURI, layout); if (manager == null) { return null; } return new RollingRandomAccessFileAppender( name, layout, filter, manager, fileName, filePattern, ignoreExceptions, isFlush, bufferSize, isAdvertise ? config.getAdvertiser() : null); }
@PluginFactory public static SyslogAppender createAppender( @PluginAttribute("host") String host, @PluginAttribute("port") String portNum, @PluginAttribute("protocol") String protocol, @PluginAttribute("reconnectionDelay") String delay, @PluginAttribute("immediateFail") String immediateFail, @PluginAttribute("name") String name, @PluginAttribute("immediateFlush") String immediateFlush, @PluginAttribute("ignoreExceptions") String ignore, @PluginAttribute("facility") String facility, @PluginAttribute("id") String id, @PluginAttribute("enterpriseNumber") String ein, @PluginAttribute("includeMDC") String includeMDC, @PluginAttribute("mdcId") String mdcId, @PluginAttribute("mdcPrefix") String mdcPrefix, @PluginAttribute("eventPrefix") String eventPrefix, @PluginAttribute("newLine") String includeNL, @PluginAttribute("newLineEscape") String escapeNL, @PluginAttribute("appName") String appName, @PluginAttribute("messageId") String msgId, @PluginAttribute("mdcExcludes") String excludes, @PluginAttribute("mdcIncludes") String includes, @PluginAttribute("mdcRequired") String required, @PluginAttribute("format") String format, @PluginElement("Filters") Filter filter, @PluginConfiguration Configuration config, @PluginAttribute("charset") String charsetName, @PluginAttribute("exceptionPattern") String exceptionPattern, @PluginElement("LoggerFields") LoggerFields[] loggerFields, @PluginAttribute("advertise") String advertise) { boolean isFlush = Booleans.parseBoolean(immediateFlush, true); boolean ignoreExceptions = Booleans.parseBoolean(ignore, true); int reconnectDelay = AbstractAppender.parseInt(delay, 0); boolean fail = Booleans.parseBoolean(immediateFail, true); int port = AbstractAppender.parseInt(portNum, 0); boolean isAdvertise = Boolean.parseBoolean(advertise); Layout<? extends Serializable> layout = "RFC5424".equalsIgnoreCase(format) ? RFC5424Layout.createLayout( facility, id, ein, includeMDC, mdcId, mdcPrefix, eventPrefix, includeNL, escapeNL, appName, msgId, excludes, includes, required, exceptionPattern, "false", loggerFields, config) : SyslogLayout.createLayout(facility, includeNL, escapeNL, charsetName); if (name == null) { LOGGER.error("No name provided for SyslogAppender"); return null; } Protocol p = (Protocol) EnglishEnums.valueOf(Protocol.class, protocol); AbstractSocketManager manager = createSocketManager(p, host, port, reconnectDelay, fail, layout); if (manager == null) { return null; } return new SyslogAppender( name, layout, filter, ignoreExceptions, isFlush, manager, isAdvertise ? config.getAdvertiser() : null); }