java - How do I change a remote application's logback log level through http (rest)? -
how change remote application's logback log level through http (rest)? to
@controller public class changelog2controller { @postmapping("/api/testlog1") public responsemodel testlogeback(@requestbody loglevelmodel levelmodel) { ... } }
something ...
@postmapping("/api/testlog1") public responsemodel testlogeback(@requestbody loglevelmodel levelmodel) { // change log level root logger logger rootlogger = (logger) loggerfactory.getlogger(logger.root_logger_name); rootlogger.setlevel(...); // change log level specific logger loggercontext loggercontext = (loggercontext) loggerfactory.getiloggerfactory(); logger specificlogger = loggercontext.getlogger("com.some.specific.package"); specificlogger.setlevel(...); }
... parameter passed setlevel()
level.info
would, presume, derived loglevelmodel
.
note: if looking way dynamically change logging configuration , jmx client (rather http client) suffice logback provides jmx configurator yuou can engage adding following logback.xml: <jmxconfigurator />
. exposes jmx mbean can use view , set log levels.
edit 1: based on comments below seems requirement might invoke webapplicationa
, somehow enable webapplicationa
change log level loggers inside webapplicationb
? if so, either
webapplicationa
has use jmxconfigurator mbean exposedwebapplicationb
. there examples of java jmx clients here , here. however, in order expose jmxconfigurator must have control onwebapplicationb
's logback.xml and, if so, perhaps have control onwebapplicationb
's implementation in case might easier expose simplesetloglevel
rest endpoint inwebapplicationb
, letwebapplicationa
invoke rather playing around java jmx client.or
webapplicationb
has exposechangeloglevel
rest api (with implementation 1 provided above)webapplicationa
can invoke.
the other alternative webapplicationa
somehow changes logback.xml used webapplicationb
, webapplicationb
's logback.xml starts looks ...
<configuration scan="true" scanperiod="30 seconds" > ... </configuration>
... changes made file on webapplicationb
's classpath picked within (for example) 30 seconds. but, since webapplicationb
's logback.xml embedded in war (or similar) approach seems awkward , undesireable.
Comments
Post a Comment