How do I change log level in runtime without restarting Spring Boot application
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Changing log levels at runtime is a practical way to debug production issues without restarting services. In Spring Boot, you can do this safely through Actuator or programmatic APIs. The important part is not only changing levels, but also controlling scope, security, and rollback.
Actuator-Based Runtime Log Control
The most common method uses the Actuator loggers endpoint. First, include Actuator and expose the endpoint.
Check current logger state:
Set logger to debug:
Reset to inherited level:
Changes apply immediately, no restart needed.
Programmatic Changes with LoggingSystem
If you need internal admin workflows, use LoggingSystem from application code.
This is useful when the change should be triggered from an internal endpoint or admin console.
Secure the Control Path
Runtime log controls are operationally sensitive. If exposed without protection, an attacker can increase log volume and potentially leak sensitive information.
Minimum safeguards:
- Require authentication and strict authorization.
- Limit access to internal networks.
- Audit who changed which logger and when.
- Add rate limiting for repeated changes.
Spring Security example for actuator protection:
Scope Changes Carefully
Do not set root logger to debug unless absolutely necessary. Prefer package-level or class-level changes.
Good:
- '
com.example.payment' - '
com.example.payment.retry.RetryService'
Risky:
- '
ROOT'
Narrow scope reduces performance impact and makes logs easier to analyze.
Multi-Instance and Cloud Behavior
In distributed deployments, changing one instance does not automatically change others. If you run many replicas, decide whether changes should be:
- Instance-local for targeted debugging.
- Cluster-wide through an orchestrated control plane.
If you need cluster-wide behavior, combine runtime changes with service discovery or an operations script that applies updates across instances.
Rollback and Time-Limited Debugging
Verbose logging can increase latency, storage usage, and log-ingestion cost. Define rollback policy before enabling debug.
A practical workflow:
- Record baseline logger level.
- Enable debug on narrow namespace.
- Collect evidence for a fixed window.
- Restore previous level automatically.
You can implement time-limited changes using scheduled tasks:
Operational Verification
Keep a short runbook with known logger names for critical modules so responders do not waste time guessing package paths during incidents. After changing levels, verify effect quickly:
- Confirm endpoint returns expected configured level.
- Confirm new debug lines appear for target package only.
- Monitor request latency and log throughput.
Without verification, teams often assume logging changed while the target logger name was incorrect.
Common Pitfalls
- Exposing
/actuator/loggerspublicly without authorization. - Enabling debug at root level during peak traffic.
- Forgetting to revert temporary logging changes.
- Assuming one instance change affects all replicas.
- Using incorrect logger names and collecting no useful output.
Summary
- Spring Boot supports live log-level changes without restart.
- Actuator
loggersendpoint is the fastest operational approach. - '
LoggingSystemis useful for internal admin-driven control.' - Secure, audit, and scope logging changes carefully.
- Always plan rollback to avoid long-running verbose logging.

