Java slf4j Logger extractValue(String var)

Here you can find the source of extractValue(String var)

Description

This method will fetch and return the value of 'var' from system variables and if not found in system variables then in environment variables.

License

Open Source License

Parameter

Parameter Description
var name of var enclosed by ${ and }

Return

value of var

Declaration

public static String extractValue(String var) 

Method Source Code

//package com.java2s;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {
    static final Logger LOGGER = LoggerFactory
            .getLogger("com.force.sdk.connector");

    /**//from www.  j  a  va  2 s  . c om
     * This method will fetch and return the value of 'var' from system variables and if not found in system variables
     * then in environment variables.
     * @param var name of var enclosed by ${ and }
     * @return value of var
     */
    public static String extractValue(String var) {
        if (var != null) {
            if (!var.startsWith("${") || !var.endsWith("}")) {
                return null;
            }

            var = var.replace("${", "");
            var = var.substring(0, var.length() - 1);

            if (var != null) {
                if (System.getProperty(var) != null) {
                    LOGGER.info("Connection : loading " + var
                            + " from Java System Properties");
                    return System.getProperty(var);
                }

                if (System.getenv(var) != null) {
                    LOGGER.info("Connection : loading " + var
                            + " from Environment Variables");
                    return System.getenv(var);
                }
            }
        }

        return null;
    }
}

Related

  1. error(Logger log, String fmt, String... args)
  2. error(Logger logger, Exception e)
  3. error(String errorMessage, Throwable e)
  4. error(String msg, Throwable e)
  5. ExecptionLog(Logger log, String msg, Throwable e)
  6. findMarker(Marker marker, String name)
  7. format(final String pattern, final @Nullable Object... arguments)
  8. format(String format, Object... args)
  9. format(String messagePattern, Object... args)