Learnitweb

Set different logging levels for specific packages in Spring Boot

To set different logging levels for specific packages in a Spring Boot application, you can configure them using the application.properties or application.yml file.

This allows you to control how much logging detail you get per package (e.g., your own code, Spring internals, Hibernate, etc.), which is useful for debugging specific modules without cluttering the logs.

Step-by-Step: Set Logging Levels in Spring Boot

1. Using application.properties

# Root logger level (global)
logging.level.root=INFO

# Set DEBUG for your application's packages
logging.level.com.example.myapp=DEBUG

# Reduce Spring logs to WARN
logging.level.org.springframework=WARN

# Show Hibernate SQL logs
logging.level.org.hibernate.SQL=DEBUG

# Hide Hibernate parameter logs
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

2. Using application.yml

logging:
  level:
    root: INFO
    com.example.myapp: DEBUG
    org.springframework: WARN
    org.hibernate.SQL: DEBUG
    org.hibernate.type.descriptor.sql.BasicBinder: TRACE

Common Log Levels (in order of verbosity)

LevelDescription
TRACEMost detailed, for fine-grained diagnostics
DEBUGDetailed info useful for debugging
INFOGeneral application flow messages
WARNPotential issues or warnings
ERRORErrors that prevent normal flow
OFFDisable logging completely

Tips

  • Always keep logging.level.root=INFO in production unless troubleshooting.
  • Use TRACE or DEBUG only for development – they can generate huge logs.
  • If you use external logging frameworks like Logback or Log4j2, you can fine-tune more settings in logback-spring.xml or log4j2-spring.xml.

Example Use Case

You are debugging a bug in your repository layer.

logging.level.com.example.myapp.repository=DEBUG

You want to see the actual SQL run by Hibernate:

logging.level.org.hibernate.SQL=DEBUG

Check Active Log Levels at Runtime (with Spring Actuator)

If you’re using Spring Boot Actuator:

  1. Add this to application.properties: management.endpoints.web.exposure.include=loggers
  2. Check active log levels: GET /actuator/loggers
  3. Change logging level at runtime: POST /actuator/loggers/com.example.myapp { "configuredLevel": "DEBUG" }