[logback-user] JMX on a WebSphere clustered environment

ceki ceki at qos.ch
Thu May 31 13:09:43 CEST 2012


Roy's idea of using  LoggerContextListener in conjunction with 
websphere's DynamicCache makes sense as well.

On 31.05.2012 01:36, Roy Cronise wrote:
> Chris, Since you are using websphere you could use the Dynamic cache
> to push the logging levels around to all the servers in the cluster.
>
> You would need to implement a LoggerContextListener to update the
> Dynamic cache when a log level changes.  Something like this:
>
> public class LogbackContextListener implements LoggerContextListener {
>       private static final String LOG_ID = "LBLOG:";
>       public void onLevelChange(Logger logger, Level level)  {
>            if (DynamicCacheAccessor.isCachingEnabled()) {
>                 DistributedMap map = DynamicCacheAccessor.getDistributedMap();
>                 map.put(LOG_ID + logger.getName(),
> level,1,60,60,EntryInfo.SHARED_PUSH, null);  //Update dynamic cache
> and push to other servers
>        }
> }
>
> and a Dynamic Cache ChangeListener, something like this:
>
> public class LogbackCacheChangeListener implements ChangeListener {
>     public void cacheEntryChanged(ChangeEvent changeEvent) {
>          if (ChangeEvent.LOCAL != changeEvent.getSourceOfChance()) {
> //Level not changed on this server then nothing to do
>               if
> (changeEvent.getId().toString().startswith(LogbackContextListener.LOG_ID))
> {  //Log level changed in cache?
>                   LoggerContext lc = (LoggerContext)
> LoggerFactory.getILoggerFactory();
>                   String loggerName =
> changeEvent.getId().toString().substring(LogbackContextListener.LOG_ID.length());
>                    Logger logger = lc.getLogger(loggerName);
>                    logger.setLevel((Level)changeEvent.getValue());
> //set logger level on server to what was pushed in cache.
>               }
>          }
>      }
>
> Sorry for any typos...
>
>
> Roy

-- 
Ceki
http://twitter.com/#!/ceki


More information about the Logback-user mailing list