Created
November 5, 2015 08:12
-
-
Save dahankzter/d63fd493a44ff1fde955 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
public ApplicationContextHolder applicationContextHolder() { | |
return new ApplicationContextHolder(); | |
} | |
@Bean | |
public LoggerContext loggerContext() { | |
return (LoggerContext) LoggerFactory.getILoggerFactory(); | |
} | |
@Bean (initMethod = "start", destroyMethod = "stop") | |
public PatternLayoutEncoder encoder (LoggerContext ctx) { | |
PatternLayoutEncoder encoder = new PatternLayoutEncoder(); | |
encoder.setContext(ctx); | |
encoder.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level [%X{EniroCaller}] %logger{50} - %msg%n"); | |
return encoder; | |
} | |
@Primary | |
@Bean (initMethod = "start", destroyMethod = "stop") | |
public ConsoleAppender consoleAppender (LoggerContext ctx, PatternLayoutEncoder encoder) { | |
ConsoleAppender appender = new ConsoleAppender(); | |
appender.setContext(ctx); | |
appender.setEncoder(encoder); | |
return appender; | |
} | |
@Qualifier(value = "accessLogs") | |
@Bean (name = "encoderAccessLogs", initMethod = "start", destroyMethod = "stop") | |
public PatternLayoutEncoder encoderAccessLogs (LoggerContext ctx) { | |
PatternLayoutEncoder encoder = new PatternLayoutEncoder(); | |
encoder.setContext(ctx); | |
encoder.setPattern("%h %l %u %t \"%r\" %s %b %D"); | |
return encoder; | |
} | |
@Bean (name = "appenderAccessLogs", initMethod = "start", destroyMethod = "stop") | |
public ConsoleAppender consoleAppenderAccessLogs (LoggerContext ctx, | |
@Qualifier(value = "encoderAccessLogs") PatternLayoutEncoder encoder) { | |
ConsoleAppender appender = new ConsoleAppender(); | |
appender.setContext(ctx); | |
appender.setEncoder(encoder); | |
return appender; | |
} | |
@Bean | |
public EmbeddedServletContainerCustomizer containerCustomizer(@Qualifier(value = "appenderAccessLogs") ConsoleAppender consoleAppender){ | |
return factory -> { | |
if(factory instanceof TomcatEmbeddedServletContainerFactory){ | |
TomcatEmbeddedServletContainerFactory containerFactory = (TomcatEmbeddedServletContainerFactory) factory; | |
LogbackValve logbackValve = new LogbackValve(); | |
logbackValve.addAppender(consoleAppender); | |
containerFactory.addContextValves(logbackValve); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment