log4j2:以编程方式设置append = false

时间:2018-03-24 02:16:37

标签: java logging log4j

我有以下代码,但我真的很难用log4j文档。 如何将append = false设置为我的文件追加器,因此每次运行都会得到一个新文件?

ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory
                .newConfigurationBuilder();

        builder.setStatusLevel(Level.ERROR);
        builder.setConfigurationName("IkodaLogBuilder");

        AppenderComponentBuilder appenderBuilder =    ........


        LayoutComponentBuilder layoutBuilder = builder.newLayout("PatternLayout").addAttribute("pattern",
                "%d [%t] %-5level: %msg%n");

        appenderBuilder = builder.newAppender("file", "File").addAttribute("fileName", "./logs/ikoda.log")
                .add(layoutBuilder);
        builder.add(appenderBuilder);

0 个答案:

没有答案