getProperty ( )源码实例Demo

java.util.logging.LogManager#getProperty ( )源码实例Demo

下面列出了java.util.logging.LogManager#getProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: syslog-java-client   文件: LogManagerHelper.java
/**
 * Visible version of {@link java.util.logging.LogManager#getFilterProperty(String, java.util.logging.Filter)}.
 *
 * We return an instance of the class named by the "name" property.
 *
 * If the property is not defined or has problems we return the defaultValue.
 */
@Nullable
public static Filter getFilterProperty(@Nonnull LogManager manager, @Nullable String name, @Nullable Filter defaultValue) {
    if (name == null) {
        return defaultValue;
    }
    String val = manager.getProperty(name);
    try {
        if (val != null) {
            Class clz = ClassLoader.getSystemClassLoader().loadClass(val);
            return (Filter) clz.newInstance();
        }
    } catch (Exception ex) {
        // We got one of a variety of exceptions in creating the
        // class or creating an instance.
        // Drop through.
    }
    // We got an exception.  Return the defaultValue.
    return defaultValue;
}
 
源代码2 项目: syslog-java-client   文件: LogManagerHelper.java
/**
 * Visible version of {@link java.util.logging.LogManager#getFormatterProperty(String, java.util.logging.Formatter)} .
 *
 * We return an instance of the class named by the "name" property.
 *
 * If the property is not defined or has problems we return the defaultValue.
 */
public static Formatter getFormatterProperty(@Nonnull LogManager manager, @Nullable String name, @Nullable Formatter defaultValue) {
    if (name == null) {
        return defaultValue;
    }
    String val = manager.getProperty(name);
    try {
        if (val != null) {
            Class clz = ClassLoader.getSystemClassLoader().loadClass(val);
            return (Formatter) clz.newInstance();
        }
    } catch (Exception ex) {
        // We got one of a variety of exceptions in creating the
        // class or creating an instance.
        // Drop through.
    }
    // We got an exception.  Return the defaultValue.
    return defaultValue;
}
 
源代码3 项目: syslog-java-client   文件: LogManagerHelper.java
/**
 * Visible version of {@link java.util.logging.LogManager#getIntProperty(String, int)}.
 *
 * Method to get a boolean property.
 *
 * If the property is not defined or cannot be parsed we return the given default value.
 */
public static boolean getBooleanProperty(@Nonnull LogManager manager, @Nullable String name, boolean defaultValue) {
    if (name == null) {
        return defaultValue;
    }
    String val = manager.getProperty(name);
    if (val == null) {
        return defaultValue;
    }
    val = val.toLowerCase();
    if (val.equals("true") || val.equals("1")) {
        return true;
    } else if (val.equals("false") || val.equals("0")) {
        return false;
    }
    return defaultValue;
}
 
源代码4 项目: java-cloudant   文件: HttpConnection.java
public HttpConnection(String requestMethod,
                      URL url,
                      String contentType) {
    this.requestMethod = requestMethod;
    this.url = url;
    this.contentType = contentType;
    this.requestProperties = new HashMap<String, String>();
    this.requestInterceptors = new LinkedList<HttpConnectionRequestInterceptor>();
    this.responseInterceptors = new LinkedList<HttpConnectionResponseInterceptor>();

    // Calculate log filter for this request if logging is enabled
    if (logger.isLoggable(Level.FINE)) {
        LogManager m = LogManager.getLogManager();
        String httpMethodFilter = m.getProperty("com.cloudant.http.filter.method");
        String urlFilter = m.getProperty("com.cloudant.http.filter.url");
        if (httpMethodFilter != null) {
            // Split the comma separated list of methods
            List<String> methods = Arrays.asList(httpMethodFilter.split(","));
            requestIsLoggable = requestIsLoggable && methods.contains(requestMethod);
        }
        if (urlFilter != null) {
            requestIsLoggable = requestIsLoggable && url.toString().matches(urlFilter);
        }
    }
}
 
源代码5 项目: reef   文件: ThreadLogFormatter.java
public ThreadLogFormatter() {

    super();
    final LogManager logManager = LogManager.getLogManager();
    final String className = this.getClass().getName();

    final String format = logManager.getProperty(className + ".format");
    this.logFormat = format != null ? format : DEFAULT_FORMAT;

    final String rawDropStr = logManager.getProperty(className + ".dropPrefix");
    if (rawDropStr != null) {
      for (String prefix : rawDropStr.trim().split(",")) {
        prefix = prefix.trim();
        if (!prefix.isEmpty()) {
          this.dropPrefix.add(prefix);
        }
      }
    }
  }
 
源代码6 项目: syslog-java-client   文件: LogManagerHelper.java
/**
 * Visible version of {@link java.util.logging.LogManager#getLevelProperty(String, java.util.logging.Level)}.
 *
 * If the property is not defined or cannot be parsed we return the given default value.
 */
@Nullable
public static Level getLevelProperty(@Nonnull LogManager manager, @Nonnull String name, @Nullable Level defaultValue) {
    if (name == null) {
        return defaultValue;
    }
    String val = manager.getProperty(name);
    if (val == null) {
        return defaultValue;
    }
    Level l = LevelHelper.findLevel(val.trim());
    return l != null ? l : defaultValue;
}
 
源代码7 项目: syslog-java-client   文件: LogManagerHelper.java
/**
 * Visible version of {@link java.util.logging.LogManager#getStringProperty(String, String)}.
 *
 * If the property is not defined we return the given default value.
 */
public static String getStringProperty(@Nonnull LogManager manager, @Nullable String name, String defaultValue) {
    if (name == null) {
        return defaultValue;
    }
    String val = manager.getProperty(name);
    if (val == null) {
        return defaultValue;
    }
    return val.trim();
}
 
源代码8 项目: syslog-java-client   文件: LogManagerHelper.java
/**
 * Visible version of {@link java.util.logging.LogManager#getIntProperty(String, int)}.
 *
 * Method to get an integer property.
 *
 * If the property is not defined or cannot be parsed we return the given default value.
 */
public static int getIntProperty(@Nonnull LogManager manager, @Nullable String name, int defaultValue) {
    if (name == null) {
        return defaultValue;
    }
    String val = manager.getProperty(name);
    if (val == null) {
        return defaultValue;
    }
    try {
        return Integer.parseInt(val.trim());
    } catch (Exception ex) {
        return defaultValue;
    }
}
 
源代码9 项目: buck   文件: ConsoleHandler.java
private static Level getLogLevelFromProperty(LogManager logManager, Level defaultLevel) {
  String levelStr = logManager.getProperty(ConsoleHandler.class.getName() + ".level");
  if (levelStr != null) {
    return Level.parse(levelStr);
  } else {
    return defaultLevel;
  }
}
 
源代码10 项目: tomee   文件: BackgroundTaskRunner.java
private static String getProperty(final LogManager logManager, final String key) {
    final String val = logManager.getProperty(key);
    return val != null ? val : System.getProperty(key);
}