Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot log4j pattern

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?

like image 923
Amin Abu-Taleb Avatar asked Jul 25 '16 14:07

Amin Abu-Taleb


2 Answers

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.

like image 164
Zvonko Avatar answered Oct 21 '22 22:10

Zvonko


Spring Boot Default Logback Configuration

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}";
like image 27
Kyle Anderson Avatar answered Oct 21 '22 22:10

Kyle Anderson