Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2016 Martin Winandy
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.tinylog.configuration;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.regex.Pattern;
import org.tinylog.Level;
import org.tinylog.provider.InternalLogger;
import org.tinylog.runtime.RuntimeProvider;
/**
* Global configuration for tinylog.
*
*
* By default, the configuration will be loaded from {@code tinylog.properties} in the default package. Another
* configuration file can be loaded by setting the system property {@code tinylog.configuration}. The configuration file
* can be a resource in the classpath, a file from file system or an URL
*
*
*
* Alternately configuration properties can be set via system properties. These properties must be prefixed by
* "{@code tinylog.}". For example: "{@code level = debug}" becomes "{@code tinylog.level=debug}". If a configuration
* property exists as system property and in configuration file, the system property will win.
*
*/
public final class Configuration {
private static final int MAX_LOCALE_ARGUMENTS = 3;
private static final String[] CONFIGURATION_FILES = new String[] {
"tinylog-dev.properties",
"tinylog-test.properties",
"tinylog.properties"
};
private static final String PROPERTIES_PREFIX = "tinylog.";
private static final String CONFIGURATION_PROPERTY = PROPERTIES_PREFIX + "configuration";
private static final String LOCALE_KEY = "locale";
private static final String ESCAPING_ENABLED_KEY = "escaping.enabled";
private static final Pattern URL_DETECTION_PATTERN = Pattern.compile("^[a-zA-Z]{2,}:/.*");
private static final Properties properties = load();
/** */
private Configuration() {
}
/**
* Gets the global locale.
*
* @return Locale from property {@code locale} or {@link Locale#ROOT} if no locale is configured
*/
public static Locale getLocale() {
String tag = get(LOCALE_KEY);
if (tag == null) {
return Locale.ROOT;
} else {
String[] splitTag = tag.split("_", MAX_LOCALE_ARGUMENTS);
if (splitTag.length == 1) {
return new Locale(splitTag[0]);
} else if (splitTag.length == 2) {
return new Locale(splitTag[0], splitTag[1]);
} else {
return new Locale(splitTag[0], splitTag[1], splitTag[2]);
}
}
}
/**
* Checks whether escaping is enabled or disabled.
*
* @return {@code true} if escaping is enabled, otherwise {@code false}
*/
public static boolean isEscapingEnabled() {
return Boolean.parseBoolean(get(ESCAPING_ENABLED_KEY));
}
/**
* Gets a configuration property. Keys a case-sensitive.
*
* @param key
* Case-sensitive key of property
* @return Found value or {@code null}
*/
public static String get(final String key) {
return (String) properties.get(key);
}
/**
* Gets all siblings with a defined prefix. Child properties will be not returned.
*
*
* Example:
*
*
*
* {@code getSiblings("writer")} will return properties with the keys {@code writer} as well as {@code writerTest}
* but not with the key {@code writer.test}. Dots after a prefix ending with an at sign will be not handled as
* children. Therefore, {@code getSiblings("level@")} will return a property with the key {@code [email protected]}.
*
*
* @param prefix
* Case-sensitive prefix for keys
* @return All found properties (map will be empty if there are no matching properties)
*/
public static Map getSiblings(final String prefix) {
Map map = new HashMap();
for (Enumeration