3
votes

We are using JBoss Enterprise Application Platform server ie. JBOSS EAP 6.1 for our new web applications that use Logback for logging. We are using JBoss EAP for some months now and everything works out cool. Also, as you may know, you can deploy and undeploy applications and config files (like e.g. the mail-service.xml) during runtime on JBOSS AS i.e. without restarting the server.

But if you change the logback.xml config file though on JBoss EAP deployed in temp directory, JBOSS EAP is not recognizing changes and on restarting the server this JBOSS EAP server deletes the changed file and re-deploy the complete new package. This is a bit annoying - it seems strange that the logaback config can not 'hot swap' while the server is running.

Setup done for auto-reloading :

-- We have configured the logback by setting the scan variable to true and scanPeriod to 5 seconds.

Are there easy ways to work around this, i.e. make it possible to 'hot swap' the logback config file on JBOSS EAP 6.1?

3
Can't you change your configuration throughthe CLI? docs.jboss.org/author/display/AS72/How+To - StephaneM

3 Answers

1
votes

You can put logback.xml in your configuration folder and then load its configuration programmaticaly. In this way auto reloading setting should work as expected. You can load configuation using Joran Configurator.

Here is a sample code snippet

    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(loggerContext);
    loggerContext.reset();
    configurator.doConfigure(LOGBACK_FILE_PATH);
0
votes

If you want to update it on the disk, don't use deployment mechanism for your logback configuration (from where it would get unpackaged into your tmp directory), but store it outside of your app, in the properties/configuration folder. Then point to it referencing to a file in the disk instead of classpath. Autoscan should work as expected after that.

If you use deployment mechanism, all updates have to go through deployment mechanism as well.


Update:

If i keep the logback configuration outside of our my app in the configuration folder, in that case we have to load and intialize the logback configuration programatticaly and i think in that case the default logback autoscanner will not work,because it always looks for the logback configuration file in classpath of webapp. So here i have to write my custom autoscanner, which i don't want to do. Did you ever tried this in JBOSS EAP. ??

I don't see why autoscanner wouldn't work with file paths. Even the manual entry provides the path to logback configuration file as a startup parameter, and then instructs how to enable autoscan using scan="true", so it should work.

We actually have a project configured using startup parameter with EAP, though it doesn't use scanning as we don't have need for it. What we do is we provide the path to logback folder as a startup parameter, then use logbackconfiglistener if it's a war, a startup bean and JoranConfigurator.doConfigure() if it's an .ear.

One case where autoscan wouldn't work and only classpath is supported is when logbackconfiglistener in web.xml is used. Here's some discussion on how to circumvent that.