Change Application Log Levels via Rabbit MQ messages at Runtime.
- Great for large scale systems where you'd like to dynamically change your log levels on multiple application instances without requiring code changes.
Upon install, this will create a new Rabbit Exchange for you called logLevelExchange of type fanout
Via Controller
-
Make sure you have a mapping in UrlMappings to
logLevel/$actionand any security permissions -
A controller
LogLevelControllerand view are provided to change the log levels from. Simply go to http[s]://yourapp.com/logLevel -
Simply fill in the form and submit. App Name is the application you would like to change the log level for.
LogLevelConsumermatches Grails application.properties "app.name" against the one that is passed in from the form.
NOTE: Highly recommend you lock down logLevel endpoint via Spring Security.
Via Service
- Inject logLevelService into your services or controllers :
- Create a
DynamicLogLevelMsg
appNameis the Application name you want to target. Uses Grails application.properties "app.name"loggerNameis the package or class you would like to change the log level forlogLevelis log level as a String you would like to change to: ['ALL','DEBUG','ERROR','FATAL','INFO','OFF','TRACE','WARN']
Example
class Foo {
def logLevelService
def changeAllServiceLogLevelsToInfo() {
logLevelService.send new DynamicLogLevelMsg("myApp", "grails.app.services", "INFO")
}
}
Thanks to Burt Beckwith for his contributions & feedback.