Java Code Examples for com.alipay.sofa.common.utils.StringUtil#isBlank()

The following examples show how to use com.alipay.sofa.common.utils.StringUtil#isBlank() . 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: CommonLoggingApplicationListener.java    From sofa-common-tools with Apache License 2.0 5 votes vote down vote up
private void readLogConfiguration(String key, String value, Map<String, String> context,
                                  String defaultValue) {
    if (!StringUtil.isBlank(value)) {
        context.put(key, value);
    } else {
        context.put(key, defaultValue);
    }
}
 
Example 2
Source File: SystemPropertiesGetter.java    From sofa-common-tools with Apache License 2.0 5 votes vote down vote up
public String getProperty(String key) {
    String value = System.getProperty(key);
    if (StringUtil.isBlank(value)) {
        return (String) properties.get(key);
    }
    return value;
}
 
Example 3
Source File: DefaultLog4j2ReInitializer.java    From sofa-common-tools with Apache License 2.0 5 votes vote down vote up
private Level getConsoleLevel(String spaceId, Properties properties) {
    SystemPropertiesGetter propertiesGetter = new SystemPropertiesGetter(properties);
    String level = propertiesGetter.getProperty(SOFA_MIDDLEWARE_ALL_LOG_CONSOLE_LEVEL);
    String defaultLevel = StringUtil.isBlank(level) ? "INFO" : level;
    level = propertiesGetter.getProperty(
        String.format(SOFA_MIDDLEWARE_SINGLE_LOG_CONSOLE_LEVEL, spaceId), defaultLevel);
    return Level.toLevel(level, Level.INFO);
}
 
Example 4
Source File: DefaultLog4j2ReInitializer.java    From sofa-common-tools with Apache License 2.0 5 votes vote down vote up
private boolean isConsoleAppenderOpen(String spaceId, Properties properties) {
    SystemPropertiesGetter propertiesGetter = new SystemPropertiesGetter(properties);
    String value = propertiesGetter.getProperty(String.format(
        SOFA_MIDDLEWARE_SINGLE_LOG_CONSOLE_SWITCH, spaceId));
    if (StringUtil.isBlank(value)) {
        return "true".equalsIgnoreCase(propertiesGetter
            .getProperty(SOFA_MIDDLEWARE_ALL_LOG_CONSOLE_SWITCH));
    } else {
        return "true".equalsIgnoreCase(value);
    }
}
 
Example 5
Source File: DefaultLogbackReInitializer.java    From sofa-common-tools with Apache License 2.0 5 votes vote down vote up
private Level getConsoleLevel(String spaceId, Properties properties) {
    SystemPropertiesGetter propertiesGetter = new SystemPropertiesGetter(properties);
    String level = propertiesGetter.getProperty(SOFA_MIDDLEWARE_ALL_LOG_CONSOLE_LEVEL);
    String defaultLevel = StringUtil.isBlank(level) ? "INFO" : level;
    level = propertiesGetter.getProperty(
        String.format(SOFA_MIDDLEWARE_SINGLE_LOG_CONSOLE_LEVEL, spaceId), defaultLevel);
    return Level.toLevel(level, Level.INFO);
}
 
Example 6
Source File: DefaultLogbackReInitializer.java    From sofa-common-tools with Apache License 2.0 5 votes vote down vote up
private boolean isConsoleAppenderOpen(String spaceId, Properties properties) {
    SystemPropertiesGetter propertiesGetter = new SystemPropertiesGetter(properties);
    String value = propertiesGetter.getProperty(String.format(
        SOFA_MIDDLEWARE_SINGLE_LOG_CONSOLE_SWITCH, spaceId));
    if (StringUtil.isBlank(value)) {
        return "true".equalsIgnoreCase(propertiesGetter
            .getProperty(SOFA_MIDDLEWARE_ALL_LOG_CONSOLE_SWITCH));
    } else {
        return "true".equalsIgnoreCase(value);
    }
}
 
Example 7
Source File: LogbackIntegrationTest.java    From sofa-common-tools with Apache License 2.0 5 votes vote down vote up
protected File getLogbackDefaultFile(Environment environment) {
    String loggingRoot = environment.getProperty(Constants.LOG_PATH_PREFIX + TEST_SPACE);
    if (StringUtil.isBlank(loggingRoot)) {
        loggingRoot = environment.getProperty(Constants.LOG_PATH);
    }
    return new File(loggingRoot + File.separator + "test-space" + File.separator
                    + "logback-common-default.log");
}
 
Example 8
Source File: LogbackLoggerSpaceFactory.java    From sofa-common-tools with Apache License 2.0 5 votes vote down vote up
public void reInitialize(Map<String, String> environment) {
    properties.putAll(environment);
    String spaceLoggingPath = environment.get(Constants.LOG_PATH_PREFIX
                                              + spaceId.getSpaceName());
    if (!StringUtil.isBlank(spaceLoggingPath)) {
        properties.setProperty(Constants.LOG_PATH_PREFIX + spaceId.getSpaceName(),
            spaceLoggingPath);
    } else if (Boolean.TRUE.toString().equals(properties.getProperty(IS_DEFAULT_LOG_PATH))) {
        properties.setProperty(Constants.LOG_PATH_PREFIX + spaceId.getSpaceName(),
            properties.getProperty(LOG_PATH));
    }

    String loggingLevelKey = LOG_LEVEL_PREFIX + spaceId.getSpaceName();
    if (Boolean.TRUE.toString().equals(properties.getProperty(Constants.IS_DEFAULT_LOG_LEVEL))
        && StringUtil.isBlank(environment.get(loggingLevelKey))) {
        for (int i = Constants.LOG_LEVEL.length(); i < loggingLevelKey.length(); ++i) {
            if (loggingLevelKey.charAt(i) == '.') {
                String level = environment.get(loggingLevelKey.substring(0, i + 1)
                                               + Constants.LOG_START);
                if (!StringUtil.isBlank(level)) {
                    properties.setProperty(loggingLevelKey, level);
                }
            }
        }
    }

    String spaceLoggingConfig = environment.get(String.format(Constants.LOGGING_CONFIG_PATH,
        spaceId.getSpaceName()));
    if (!StringUtil.isBlank(spaceLoggingConfig)) {
        confFile = this.getClass().getClassLoader().getResource(spaceLoggingConfig);
    }

    Iterator<LogbackReInitializer> matchers = ServiceLoader.load(LogbackReInitializer.class,
        this.getClass().getClassLoader()).iterator();
    if (matchers.hasNext()) {
        LogbackReInitializer logbackReInitializer = matchers.next();
        logbackReInitializer.reInitialize(spaceId, loggerContext, properties, confFile);
    }
}
 
Example 9
Source File: Log4j2LoggerSpaceFactory.java    From sofa-common-tools with Apache License 2.0 5 votes vote down vote up
public void reInitialize(Map<String, String> environment) {
    properties.putAll(environment);
    String spaceLoggingPath = environment.get(Constants.LOG_PATH_PREFIX
                                              + spaceId.getSpaceName());
    if (!StringUtil.isBlank(spaceLoggingPath)) {
        properties.setProperty(Constants.LOG_PATH_PREFIX + spaceId.getSpaceName(),
            spaceLoggingPath);
    } else if (Boolean.TRUE.toString().equals(properties.getProperty(IS_DEFAULT_LOG_PATH))) {
        properties.setProperty(Constants.LOG_PATH_PREFIX + spaceId.getSpaceName(),
            properties.getProperty(LOG_PATH));
    }

    String loggingLevelKey = LOG_LEVEL_PREFIX + spaceId.getSpaceName();
    if (Boolean.TRUE.toString().equals(properties.getProperty(Constants.IS_DEFAULT_LOG_LEVEL))
        && StringUtil.isBlank(environment.get(loggingLevelKey))) {
        for (int i = Constants.LOG_LEVEL.length(); i < loggingLevelKey.length(); ++i) {
            if (loggingLevelKey.charAt(i) == '.') {
                String level = environment.get(loggingLevelKey.substring(0, i + 1)
                                               + Constants.LOG_START);
                if (!StringUtil.isBlank(level)) {
                    properties.setProperty(loggingLevelKey, level);
                }
            }
        }
    }

    String spaceLoggingConfig = environment.get(String.format(Constants.LOGGING_CONFIG_PATH,
        spaceId.getSpaceName()));
    if (!StringUtil.isBlank(spaceLoggingConfig)) {
        confFile = this.getClass().getClassLoader().getResource(spaceLoggingConfig);
    }

    Iterator<Log4j2ReInitializer> matchers = ServiceLoader.load(Log4j2ReInitializer.class,
        this.getClass().getClassLoader()).iterator();
    if (matchers.hasNext()) {
        Log4j2ReInitializer log4j2ReInitializer = matchers.next();
        log4j2ReInitializer.reInitialize(spaceId, loggerContext, properties, confFile);
    }
}
 
Example 10
Source File: AbstractLoggerSpaceFactoryBuilder.java    From sofa-common-tools with Apache License 2.0 5 votes vote down vote up
private void specifySpaceLogConfigProperties(String spaceName) {
    /*
     * == 1.space's logger path
     */
    String loggingPathKey = LOG_PATH_PREFIX + spaceName;
    String defaultLoggingPath = spaceInfo.getProperty(LOG_PATH);
    if (spaceInfo.getProperty(loggingPathKey) == null) {
        spaceInfo.setProperty(IS_DEFAULT_LOG_PATH, Boolean.TRUE.toString());
        spaceInfo.setProperty(loggingPathKey, defaultLoggingPath);
    }

    /*
     * == 2.space's logger level
     */
    String loggingLevelKey = LOG_LEVEL_PREFIX + spaceName;
    if (spaceInfo.getProperty(loggingLevelKey) == null) {
        spaceInfo.setProperty(IS_DEFAULT_LOG_LEVEL, Boolean.TRUE.toString());
        spaceInfo.setProperty(loggingLevelKey, DEFAULT_MIDDLEWARE_SPACE_LOG_LEVEL);
        for (int i = LOG_LEVEL.length(); i < loggingLevelKey.length(); ++i) {
            if (loggingLevelKey.charAt(i) == '.') {
                String level = spaceInfo.getProperty(loggingLevelKey.substring(0, i + 1)
                                                     + LOG_START);
                if (!StringUtil.isBlank(level)) {
                    spaceInfo.setProperty(loggingLevelKey, level);
                }
            }
        }
    }

}
 
Example 11
Source File: CommonLoggingApplicationListener.java    From sofa-common-tools with Apache License 2.0 4 votes vote down vote up
private void addToGlobalSystemProperties(String key, String value) {
    if (!StringUtil.isBlank(key) && !StringUtil.isBlank(value)) {
        LogEnvUtils.processGlobalSystemLogProperties().put(key, value);
    }
}
 
Example 12
Source File: CommonLoggingApplicationListener.java    From sofa-common-tools with Apache License 2.0 4 votes vote down vote up
private void readLogConfiguration(String key, String value, Map<String, String> context) {
    if (!StringUtil.isBlank(value)) {
        context.put(key, value);
    }
}
 
Example 13
Source File: SystemPropertiesGetter.java    From sofa-common-tools with Apache License 2.0 4 votes vote down vote up
public String getProperty(String key, String defaultValue) {
    String value = getProperty(key);
    return StringUtil.isBlank(value) ? defaultValue : value;
}
 
Example 14
Source File: LogLog.java    From sofa-common-tools with Apache License 2.0 4 votes vote down vote up
public static void setConsoleLevel(String level) {
    Level value = LEVELS.get(level.toUpperCase());
    if (!StringUtil.isBlank(level) && value != null) {
        consoleLogLevel = value;
    }
}