public final class Configuration extends Object
By default, the configuration will be loaded from tinylog.properties
in the default package. Another
configuration file can be loaded by setting the system property 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
"tinylog.
". For example: "level = debug
" becomes "tinylog.level=debug
". If a configuration
property exists as system property and in configuration file, the system property will win.
The default property loading behavior can be changed by supplying a property service loader which reads the properties
in any other way. The properties can have a priority. The service loader which loads the properties with the highest
priority is chosen. Alternatively, the loader can be directly chosen by setting a system property
"tinylog.configurationloader
" to the simple class name of the desired loader.
Modifier and Type | Method and Description |
---|---|
static String |
get(String key)
Gets a configuration property.
|
static Map<String,String> |
getChildren(String key)
Gets all child properties for a parent property.
|
static Locale |
getLocale()
Gets the global locale.
|
static Map<String,String> |
getSiblings(String prefix)
Gets all siblings with a defined prefix.
|
static boolean |
isEscapingEnabled()
Checks whether escaping is enabled or disabled.
|
static boolean |
isFrozen()
Checks whether the configuration is already frozen.
|
static void |
mergeSystemProperties(Properties properties)
Merges system properties starting with the Tinylog property prefix into the given properties.
|
static void |
replace(Map<String,String> configuration)
Replaces the current configuration by a new one.
|
static String |
resolve(String value,
org.tinylog.configuration.Resolver resolver)
Resolves placeholders with passed resolver.
|
static void |
resolveProperties(Properties properties,
org.tinylog.configuration.Resolver... resolvers)
Resolves the given property entries with the provided resolvers.
|
static void |
set(String key,
String value)
Sets a property.
|
public static Locale getLocale()
locale
or Locale.ROOT
if no locale is configuredpublic static boolean isEscapingEnabled()
true
if escaping is enabled, otherwise false
public static String get(String key)
key
- Case-sensitive key of propertynull
public static Map<String,String> getSiblings(String prefix)
Example:
getSiblings("writer")
will return properties with the keys writer
as well as writerTest
but not with the key writer.test
. Dots after a prefix ending with an at sign will be not handled as
children. Therefore, getSiblings("level@")
will return a property with the key level@com.test
.
prefix
- Case-sensitive prefix for keyspublic static Map<String,String> getChildren(String key)
For example: getChildren("writer")
will return the property writer.level
as level
.
key
- Case-sensitive key of parent propertypublic static void set(String key, String value) throws UnsupportedOperationException
Configuration properties must be set before calling any logging methods. If the framework has been initialized
once, the configuration is immutable and further configuration changes will throw an UnsupportedOperationException
.
key
- Name of the propertyvalue
- Value of the propertyUnsupportedOperationException
- Configuration has already been applied and is frozenpublic static void replace(Map<String,String> configuration) throws UnsupportedOperationException
Configuration properties must be set before calling any logging methods. If the framework has been initialized
once, the configuration is immutable and further configuration changes will throw an UnsupportedOperationException
.
configuration
- New configurationUnsupportedOperationException
- Configuration has already been applied and is frozenpublic static String resolve(String value, org.tinylog.configuration.Resolver resolver)
value
- String with placeholdersresolver
- Resolver for replacing placeholderspublic static void mergeSystemProperties(Properties properties)
properties
- The properties which the system values shall be merged intopublic static void resolveProperties(Properties properties, org.tinylog.configuration.Resolver... resolvers)
properties
- The properties which shall be resolvedresolvers
- One or more resolvers to apply to each property entrypublic static boolean isFrozen()
true
if the configuration is frozen, otherwise false
Copyright © 2024. All rights reserved.