Reputation: 10953
I used an application.properties with Spring Boot (1.3 M1) and started to translate it into a yaml file because it grew more and more complex.
But I have problems translating this into yaml:
logging.level.*=WARN
logging.level.com.filenet.wcm=ERROR
logging.level.de.mycompany=DEBUG
The last two lines are easily translated into this:
logging:
level:
com.filenet.wcm: ERROR
de.mycompany: DEBUG
But how to add the values for the root logging level ? These two approaches failed:
Failed approach 1:
logging:
level: WARN
com.filenet.wcm: ERROR
de.mycompany: DEBUG
Failed approach 2:
logging:
level:
star: WARN
com.filenet.wcm: ERROR
de.mycompany: DEBUG
I read the docs, searched stackoverflow and googled but did not find an example for a valid syntax.
Upvotes: 95
Views: 148846
Reputation: 148
we can configure logback properties in yml file without defining custom logback-spring.xml file. Used following configuration to achieve logging along with daily rolling appender and file size appender.
logging:
logback:
rollingpolicy:
max-file-size: 10MB
file-name-pattern: /logs/archived/application-%d{yyyy-MM-dd}.%i.log
max-history: 30
file:
name: /logs/application.log
pattern:
console: "%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable"
file: "%d %-5level [%thread] %logger : %msg%n"
level: "%5p"
level:
root: INFO
com.mypackage: ERROR (--Package level ERROR only)
Upvotes: 1
Reputation: 5068
You can log incoming request by creating CommonsRequestLoggingFilter
and adding
logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=DEBUG
to application.properties
file as explained in detail in this link - https://www.baeldung.com/spring-http-logging
@Configuration
public class RequestLoggingFilterConfig {
@Bean
public CommonsRequestLoggingFilter logFilter() {
CommonsRequestLoggingFilter filter
= new CommonsRequestLoggingFilter();
filter.setIncludeQueryString(true);
filter.setIncludePayload(true);
filter.setMaxPayloadLength(10000);
filter.setIncludeHeaders(false);
filter.setAfterMessagePrefix("REQUEST DATA : ");
return filter;
}
}
Upvotes: 0
Reputation: 1297
If you want level by package, you can use this syntax :
logging:
level:
org.springframework.web: DEBUG
guru.springframework.controllers: DEBUG
org.hibernate: DEBUG
org: INFO
Upvotes: 62
Reputation: 2142
It's an old question, but I just had this problem.
While setting
org.springframework.web: debug
or
org.hibernate: debug
works fine, if you want to do the same for your project files (setting level per package), you have to use wildcards. So, for the example in the question, it would be:
logging:
level:
root: WARN
com.filenet.wcm.*: ERROR
de.mycompany.*: DEBUG
Alternatively, you can set the logging level per class without using wildcards, as shown in torina's answer.
Upvotes: 4
Reputation: 4443
You can even use your classname to configure logging level:
logging:
level:
com.yourorganization.Yourclass: DEBUG
Upvotes: 5
Reputation: 116091
You can use ROOT
to configure the root logging level:
logging:
level:
ROOT: DEBUG
Upvotes: 187