我正在以编程方式使用TimeBasedRollingPolicy配置Logback RollingFileAppender。它看起来像这样:
RollingFileAppender<ILoggingEvent> rollingAppender = new RollingFileAppender<ILoggingEvent>();
TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<ILoggingEvent>();
policy.setContext(rootLogger.getLoggerContext());
policy.setFileNamePattern(filePath + "/log.%d.txt");
policy.setMaxHistory(90);
policy.setParent(rollingAppender);
policy.start();
rollingAppender.setContext(context);
rollingAppender.setRollingPolicy(policy);
rollingAppender.setTriggeringPolicy(policy);
rollingAppender.setLayout(layout.getLayout());
rollingAppender.start();
rootLogger.addAppender(rollingAppender);
理想情况下,今天的日志将在log.txt中,之前滚动的日志将在log。%d.txt中。实际上,即使今天的日志也在log。%d.txt中。如何获取当天日志的单独日志文件名?
答案 0 :(得分:0)
使用rollingAppender.setFile("foo.txt");
。活动文件名是appender的属性,而不是策略。