Java Code Examples for java.util.logging.LogManager#getProperty()

The following examples show how to use java.util.logging.LogManager#getProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogManagerHelper.java    From syslog-java-client with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: LogManagerHelper.java    From syslog-java-client with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: LogManagerHelper.java    From syslog-java-client with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: HttpConnection.java    From java-cloudant with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example 5
Source File: ThreadLogFormatter.java    From reef with Apache License 2.0 6 votes vote down vote up
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);
        }
      }
    }
  }
 
Example 6
Source File: LogManagerHelper.java    From syslog-java-client with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: LogManagerHelper.java    From syslog-java-client with MIT License 5 votes vote down vote up
/**
 * 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();
}
 
Example 8
Source File: LogManagerHelper.java    From syslog-java-client with MIT License 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 9
Source File: ConsoleHandler.java    From buck with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example 10
Source File: BackgroundTaskRunner.java    From tomee with Apache License 2.0 4 votes vote down vote up
private static String getProperty(final LogManager logManager, final String key) {
    final String val = logManager.getProperty(key);
    return val != null ? val : System.getProperty(key);
}