Reputation: 4511
I'm moving from logback to log4j and I have to replicate the default configuration in Spring Boot for Log4j.
That's what I have so far, but it doesn't look like the previous one.
log4j.category.org.springframework=INFO
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
I'm trying to make it look like this:
2014-03-05 10:57:51.112 INFO 45469 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.52
2014-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2014-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1358 ms
2014-03-05 10:57:51.698 INFO 45469 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2014-03-05 10:57:51.702 INFO 45469 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
Where is the config file so I can check the pattern and the rest of the config and see what I'm missing?
Upvotes: 6
Views: 7022
Reputation: 301
This is the pattern you are looking for:
"%d{yyyy-MM-dd HH:mm:ss.SSS} %-4p %4L --- [%15.15t] %-40.40C : %m%n%wEx"
You will get what you want.
Upvotes: 7
Reputation: 7031
private static final String CONSOLE_LOG_PATTERN = "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} "
+ "%clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} "
+ "%clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} "
+ "%clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}";
Upvotes: 2
Reputation: 701
You may find guide which gives detailed explanation about PatternLayout from org.apache.log4j.PatternLayout
There is a sample, maybe you could get some inspiration.
<layout class="org.apache.log4j.EnhancedPatternLayout">
<param name="ConversionPattern" value="%-5p %d{yyyy-MM-dd/HH:mm:ss.SSS}{UTC} [%t] %c{1} -|%-5X{requestId}|- %m%n" />
</layout>
Application log likes:
INFO 2016-07-21/12:14:49.613 [http-nio-9040-exec-9] QrCodeTestController -|29909|- BufferedImage is BufferedImage@2e5adf04: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@4996a909 transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 556 height = 776 #numDataElements 3 dataOff[0] = 6782
Upvotes: 0