简体   繁体   中英

How to disable WARN messages and enable only INFO messages in logs through application.properties in Spring boot application?

I have tried using the below property value in my application.properties to enable only logger INFO messages. But looks like it does not work as expected. I still see the WARNING messages appear along with INFO messages. But I only want INFO messages to appear, am I doing something wrong here?

logging.level.root=INFO

2018-12-21 09:46:25.312  INFO 12364 --- [nio-8081-exec-2] c.m.s.abc.util.FileUploadUtil      : Sample message 1
2018-12-21 09:46:25.316  INFO 12364 --- [nio-8081-exec-2] c.m.service.abc.util.EnvelopeUtil  : Sample message 2
2018-12-21 09:46:25.316  INFO 12364 --- [nio-8081-exec-2] c.m.service.abc.util.EnvelopeUtil  : Sample message 3
2018-12-21 09:46:25.316  INFO 12364 --- [nio-8081-exec-2] c.m.service.abc.util.EnvelopeUtil  : Sample message 4
2018-12-21 09:46:27.813  WARN 12364 --- [nio-8081-exec-2] o.a.pdfbox.pdmodel.font.PDType0Font      : No Unicode mapping for CID+11 (11) in font ArialNarrow-Bold-Identity-H
2018-12-21 09:46:27.813  WARN 12364 --- [nio-8081-exec-2] o.a.pdfbox.pdmodel.font.PDType0Font      : No Unicode mapping for CID+48 (48) in font ArialNarrow-Bold-Identity-H
2018-12-21 09:46:27.813  WARN 12364 --- [nio-8081-exec-2] o.a.pdfbox.pdmodel.font.PDType0Font      : No Unicode mapping for CID+68 (68) in font ArialNarrow-Bold-Identity-H
2018-12-21 09:46:27.813  WARN 12364 --- [nio-8081-exec-2] o.a.pdfbox.pdmodel.font.PDType0Font      : No Unicode mapping for CID+86 (86) in font ArialNarrow-Bold-Identity-H
2018-12-21 09:46:27.814  WARN 12364 --- [nio-8081-exec-2] o.a.pdfbox.pdmodel.font.PDType0Font      : No Unicode mapping for CID+88 (88) in font ArialNarrow-Bold-Identity-H
2018-12-21 09:46:27.814  WARN 12364 --- [nio-8081-exec-2] o.a.pdfbox.pdmodel.font.PDType0Font      : No Unicode mapping for CID+87 (87) in font ArialNarrow-Bold-Identity-H

You're not doing anything wrong, but none of the logging systems supported by Spring Boot (Logback, Log4j2, JUL) work as you expect. When you set the level for a particular logger, it will log everything at that level and above. As you have seen, that means that when INFO level logging is enabled, WARN (and ERROR ) messages will also be logged.

If you want to only log messages for a specific level, you'll have to use more complex configuration. For example, Logback provides a LevelFilter that provides the behaviour you want. To configure it, you'll have to use logback.xml rather than relying solely on Spring Boot's application properties.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM