private Logger findLogger(Descriptor descriptor) {
    Logger logger = getLogger();

    if (descriptor == null) {
      if (logger.isEnabledFor(Logger.TRACE)) {
        logger.trace("Can't find MBean logger, descriptor is null");
      }
      return null;
    }

    String log = (String) descriptor.getFieldValue("log");
    String location = (String) descriptor.getFieldValue("logFile");

    if (logger.isEnabledFor(Logger.DEBUG)) {
      logger.debug("Log fields: log=" + log + ", file=" + location);
    }

    if (log == null || !Boolean.parseBoolean(log)) {
      if (logger.isEnabledFor(Logger.DEBUG)) {
        logger.debug("Logging is not supported by this ModelMBean");
      }
      return null;
    }
    // Logger is supported, where log to ?
    if (location == null) {
      // As an extension, see if the field logMBean has been defined
      location = (String) descriptor.getFieldValue("logMBean");
      if (logger.isEnabledFor(Logger.DEBUG)) {
        logger.debug("Log fields: mbean=" + location);
      }

      if (location == null) {
        if (logger.isEnabledFor(Logger.TRACE)) {
          logger.trace("Logging is not supported by this ModelMBean");
        }
        return null;
      }

      // It seems that the user wants to delegate a registered mbean to log
      try {
        ObjectName objectName = new ObjectName(location);
        MBeanServer server = getMBeanServer();
        if (server == null) {
          throw new MBeanException(new IllegalStateException(
              "MX4JModelMBean is not registered."));
        }
        if (server.isRegistered(objectName)) {
          MBeanLogger l = new MBeanLogger(server, objectName);
          if (logger.isEnabledFor(Logger.DEBUG)) {
            logger.debug("ModelMBean log supported by delegating to this MBean: " + objectName);
          }
          return l;
        }

        return null;
      } catch (MalformedObjectNameException x) {
        // Ah, was not a correct object name
        if (logger.isEnabledFor(Logger.DEBUG)) {
          logger.debug("Specified logMBean field does not contain a valid ObjectName: " + location);
        }
        return null;
      } catch (MBeanException x) {
        if (logger.isEnabledFor(Logger.DEBUG)) {
          logger.debug("logMBean field does not specify an MBean that supports logging delegation",
              x);
        }
        return null;
      }
    } else {
      // User decided to log to a file
      if (logger.isEnabledFor(Logger.DEBUG)) {
        logger.debug("ModelMBean log supported on file system");
      }
      return new FileLogger(location);
    }
  }
@author <a href="mailto:biorn_steedom@users.sourceforge.net">Simone Bordet</a>
@version $Revision: 1.14 $
geode-core/src/main/java/org/apache/geode/admin/jmx/internal/MX4JModelMBean.java