Class Configuration

    • Method Detail

      • checkForUnknownFields

        public void checkForUnknownFields()
        Checks if all non-empty values in properties prefixed with prefix have been requested with optionalString(java.lang.String) (or a method using it) and throws an exception with any unused properties. When implementing an observer, call this method after you have read the whole configuration to alert the user of misconfiguration
      • containsKey

        public boolean containsKey​(String key)
        Returns true if this key (prefixed with the current context) is either in the configuration properties or an environment variable
      • listProperties

        public Set<String> listProperties​(String key)
        List all direct property names under the specified key. For example, if a Configuration with prefix "observer.test" has properties "observer.test.markers.a.foo", "observer.test.markers.a.bar" and "observer.test.markers.b", listProperties("markers") will return ["a", "b"].
      • optionalString

        public Optional<String> optionalString​(String key)
        Returns prefixed value from properties or environment. For example, if prefix is "observer.console", optionalString("threshold") will check property value "observer.console.threshold" and environment variable "LOGEVENTS_OBSERVER_CONSOLE_THRESHOLD"
      • optionalGlobalString

        public Optional<String> optionalGlobalString​(String key)
        Returns global value from properties or environment. For example, optionalString("threshold") will check property value "observer.*.threshold" and environment variable "LOGEVENTS_THRESHOLD"
      • optionalStringOrGlobal

        public Optional<String> optionalStringOrGlobal​(String key)
        Returns prefixed or global value from properties or environment. For example, if prefix is "observer.console", optionalStringOrGlobal("threshold") will check property values "observer.console.threshold" and "observer.*.threshold" and environment variables "LOGEVENTS_OBSERVER_CONSOLE_THRESHOLD" and "LOGEVENTS_CONSOLE".
      • getBoolean

        public boolean getBoolean​(String key)
      • getBoolean

        public boolean getBoolean​(String key,
                                  boolean defaultValue)
      • getStringListOrGlobal

        public List<String> getStringListOrGlobal​(String key)
      • createInstance

        public <T> T createInstance​(String key,
                                    Class<T> clazz)
        Instantiates a class with the name in the provided property name and verifies that it's a subtype of the argument class. If the class has a constructor with String, Properties, this is invoked with the argument key added to the current prefix. Otherwise, the default constructor is used.
      • createInstance

        public <T> T createInstance​(String key,
                                    Class<T> clazz,
                                    String defaultPackage)
        Instantiates a class with the name in the provided property name. If the configured class name doesn't have a package name, defaultPackage.
        See Also:
        createInstance(String, Class)
      • createInstanceWithDefault

        public <T> T createInstanceWithDefault​(String key,
                                               Class<T> defaultClass)
        Instantiates a class with the name in the provided property name and verifies that it's a subclass of the defaultClass. If no property is configured, the defaultClass is used instead
        See Also:
        createInstance(String, Class)
      • createInstanceOrGlobal

        public <T> T createInstanceOrGlobal​(String key,
                                            Class<T> targetType,
                                            Class<? extends T> defaultClass)
        Instantiates a class with the name in the provided property name and verifies that it's a subtype of the targetType. If no property is configured, the defaultClass is used instead
        See Also:
        createInstance(String, Class)
      • createInstanceWithDefault

        public <T> T createInstanceWithDefault​(String key,
                                               Class<T> targetType,
                                               Class<? extends T> defaultClass)
      • createInstanceWithDefault

        public <T> T createInstanceWithDefault​(String key,
                                               Class<? extends T> defaultClass,
                                               String packageName)
      • getMdcFilter

        public MdcFilter getMdcFilter()
        Returns a filter to determine which MDC variables to include in input. These are set either with observer.<name>.includedMdcKeys, observer.<name>.excludedMdcKeys, observer.*.includedMdcKeys, observer.*.excludedMdcKeys. Only one of the options is used and inclusion is preferred over exclusion.
      • getPackageFilter

        public List<String> getPackageFilter()
        Returns a list of classname prefixes that should be removed from stack traces
      • getLocale

        public Locale getLocale()
      • getServerUser

        public String getServerUser()
      • getApplicationNode

        public String getApplicationNode()
      • getNodeName

        public String getNodeName()
        If observer.whatever.nodeName or observer.*.nodeName is set, returns that value, otherwise returns the hostname of the computer running this JVM.
      • getApplicationName

        public String getApplicationName()
        If observer.whatever.applicationName or observer.*.applicationName is set, returns that value, otherwise calculates the name of the application based on the JAR-file of the main class. If run from a directory classpath, use the name of the current working directory instead
      • getMainClassName

        public static Optional<String> getMainClassName()
      • isRunningInTest

        public static boolean isRunningInTest()
      • getPrefix

        public String getPrefix()