我试图在Spring Boot中以编程方式配置logback。我要求不要在我的项目中使用任何XML文件。我使用logback-extensions来创建我的logback appenders等。
@Configuration
public class LoggingConfig {
@Bean
// NOTE: THIS DOES NOT DO WHAT I EXPECT IT TO
public LogbackConfigListener logbackConfigListener() {
return new LogbackConfigListener();
}
@Bean
public static ApplicationContextHolder applicationContextHolder() {
return new ApplicationContextHolder();
}
@Bean
public static LoggerContext loggerContext() {
return (LoggerContext) LoggerFactory.getILoggerFactory();
}
@Bean(initMethod = "start", destroyMethod = "stop")
public static LayoutWrappingEncoder encoder(LoggerContext ctx) {
LayoutWrappingEncoder encoder = new LayoutWrappingEncoder();
encoder.setContext(ctx);
return encoder;
}
@Bean(initMethod = "start", destroyMethod = "stop")
public static ConsoleAppender consoleAppender(LoggerContext ctx, LayoutWrappingEncoder encoder) {
ConsoleAppender appender = new ConsoleAppender();
appender.setContext(ctx);
appender.setEncoder(encoder);
return appender;
}
}
然而,我从他们的文档中得到了一个步骤。我应该在web.xml中添加一个LogbackConfigListener。我如何在Spring Boot中实现这一目标?