Java Code Examples for org.apache.logging.log4j.util.PropertiesUtil#getStringProperty()

The following examples show how to use org.apache.logging.log4j.util.PropertiesUtil#getStringProperty() . 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: ConfigurationFactory.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
public static AuthorizationProvider authorizationProvider(PropertiesUtil props) {
    final String authClass = props.getStringProperty(AUTHORIZATION_PROVIDER);
    AuthorizationProvider provider = null;
    if (authClass != null) {
        try {
            Object obj = LoaderUtil.newInstanceOf(authClass);
            if (obj instanceof AuthorizationProvider) {
                provider = (AuthorizationProvider) obj;
            } else {
                LOGGER.warn("{} is not an AuthorizationProvider, using default", obj.getClass().getName());
            }
        } catch (Exception ex) {
            LOGGER.warn("Unable to create {}, using default: {}", authClass, ex.getMessage());
        }
    }
    if (provider == null) {
        provider = new BasicAuthorizationProvider(props);
    }
    return provider;
}
 
Example 2
Source File: BasicAuthorizationProvider.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
public BasicAuthorizationProvider(PropertiesUtil props) {
    String userName = props.getStringProperty(PREFIXES,AUTH_USER_NAME,
            () -> props.getStringProperty(CONFIG_USER_NAME));
    String password = props.getStringProperty(PREFIXES, AUTH_PASSWORD,
            () -> props.getStringProperty(CONFIG_PASSWORD));
    String decryptor = props.getStringProperty(PREFIXES, AUTH_PASSWORD_DECRYPTOR,
            () -> props.getStringProperty(PASSWORD_DECRYPTOR));
    if (decryptor != null) {
        try {
            Object obj = LoaderUtil.newInstanceOf(decryptor);
            if (obj instanceof PasswordDecryptor) {
                password = ((PasswordDecryptor) obj).decryptPassword(password);
            }
        } catch (Exception ex) {
            LOGGER.warn("Unable to decrypt password.", ex);
        }
    }
    if (userName != null && password != null) {
        authString = "Basic " + encoder.encodeToString((userName + ":" + password).getBytes());
    }
}
 
Example 3
Source File: AsyncQueueFullPolicyFactory.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private static AsyncQueueFullPolicy createDiscardingAsyncQueueFullPolicy() {
    final PropertiesUtil util = PropertiesUtil.getProperties();
    final String level = util.getStringProperty(PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL, Level.INFO.name());
    final Level thresholdLevel = Level.toLevel(level, Level.INFO);
    LOGGER.debug("Creating custom DiscardingAsyncQueueFullPolicy(discardThreshold:{})", thresholdLevel);
    return new DiscardingAsyncQueueFullPolicy(thresholdLevel);
}
 
Example 4
Source File: Log4j2CloudConfigLoggingSystem.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
protected String[] getStandardConfigLocations() {
    String[] locations = super.getStandardConfigLocations();
    PropertiesUtil props = new PropertiesUtil(new Properties());
    String location = props.getStringProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
    if (location != null) {
        List<String> list = Arrays.asList(super.getStandardConfigLocations());
        list.add(location);
        locations = list.toArray(new String[0]);
    }
    return locations;
}
 
Example 5
Source File: ThreadContextMapFactory.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes static variables based on system properties. Normally called when this class is initialized by the VM
 * and when Log4j is reconfigured.
 */
private static void initPrivate() {
    final PropertiesUtil properties = PropertiesUtil.getProperties();
    ThreadContextMapName = properties.getStringProperty(THREAD_CONTEXT_KEY);
    GcFreeThreadContextKey = properties.getBooleanProperty(GC_FREE_THREAD_CONTEXT_KEY);
}
 
Example 6
Source File: ConfigurationFactory.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the ConfigurationFactory.
 * @return the ConfigurationFactory.
 */
public static ConfigurationFactory getInstance() {
    // volatile works in Java 1.6+, so double-checked locking also works properly
    //noinspection DoubleCheckedLocking
    if (factories == null) {
        LOCK.lock();
        try {
            if (factories == null) {
                final List<ConfigurationFactory> list = new ArrayList<>();
                PropertiesUtil props = PropertiesUtil.getProperties();
                final String factoryClass = props.getStringProperty(CONFIGURATION_FACTORY_PROPERTY);
                if (factoryClass != null) {
                    addFactory(list, factoryClass);
                }
                final PluginManager manager = new PluginManager(CATEGORY);
                manager.collectPlugins();
                final Map<String, PluginType<?>> plugins = manager.getPlugins();
                final List<Class<? extends ConfigurationFactory>> ordered = new ArrayList<>(plugins.size());
                for (final PluginType<?> type : plugins.values()) {
                    try {
                        ordered.add(type.getPluginClass().asSubclass(ConfigurationFactory.class));
                    } catch (final Exception ex) {
                        LOGGER.warn("Unable to add class {}", type.getPluginClass(), ex);
                    }
                }
                Collections.sort(ordered, OrderComparator.getInstance());
                for (final Class<? extends ConfigurationFactory> clazz : ordered) {
                    addFactory(list, clazz);
                }
                // see above comments about double-checked locking
                //noinspection NonThreadSafeLazyInitialization
                factories = Collections.unmodifiableList(list);
                authorizationProvider = authorizationProvider(props);
            }
        } finally {
            LOCK.unlock();
        }
    }

    LOGGER.debug("Using configurationFactory {}", configFactory);
    return configFactory;
}