java filemanager_Java RollingFileManager类代码示例

import org.apache.logging.log4j.core.appender.rolling.RollingFileManager; //导入依赖的package包/类

/**

* Create a RollingFileAppender.

* @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 bufferedIO When true, I/O will be buffered. Defaults to "true".

* @param immediateFlush When true, events are immediately flushed. Defaults to "true".

* @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 RollingFileAppender.

*/

@PluginFactory

public static RollingFileAppender createAppender(

@PluginAttribute("fileName") final String fileName,

@PluginAttribute("filePattern") final String filePattern,

@PluginAttribute("append") final String append,

@PluginAttribute("name") final String name,

@PluginAttribute("bufferedIO") final String bufferedIO,

@PluginAttribute("immediateFlush") final String immediateFlush,

@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 isBuffered = Booleans.parseBoolean(bufferedIO, true);

final boolean isFlush = Booleans.parseBoolean(immediateFlush, true);

final boolean isAdvertise = Boolean.parseBoolean(advertise);

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.createLayout(null, null, null, null, null);

}

final RollingFileManager manager = RollingFileManager.getFileManager(fileName, filePattern, isAppend,

isBuffered, policy, strategy, advertiseURI, layout);

if (manager == null) {

return null;

}

return new RollingFileAppender(name, layout, filter, manager, fileName, filePattern,

ignoreExceptions, isFlush, isAdvertise ? config.getAdvertiser() : null);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值