public final class Configuration
extends java.lang.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 | Description |
---|---|---|
static java.lang.String |
get(java.lang.String key) |
Gets a configuration property.
|
static java.util.Map<java.lang.String,java.lang.String> |
getChildren(java.lang.String key) |
Gets all child properties for a parent property.
|
static java.util.Locale |
getLocale() |
Gets the global locale.
|
static java.util.Map<java.lang.String,java.lang.String> |
getSiblings(java.lang.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(java.util.Properties properties) |
Merges system properties starting with the Tinylog property prefix into the given properties.
|
static void |
replace(java.util.Map<java.lang.String,java.lang.String> configuration) |
Replaces the current configuration by a new one.
|
static java.lang.String |
resolve(java.lang.String value,
org.tinylog.configuration.Resolver resolver) |
Resolves placeholders with passed resolver.
|
static void |
resolveProperties(java.util.Properties properties,
org.tinylog.configuration.Resolver... resolvers) |
Resolves the given property entries with the provided resolvers.
|
static void |
set(java.lang.String key,
java.lang.String value) |
Sets a property.
|
public static java.util.Locale getLocale()
locale
or Locale.ROOT
if no locale is configuredpublic static boolean isEscapingEnabled()
true
if escaping is enabled, otherwise false
public static java.lang.String get(java.lang.String key)
key
- Case-sensitive key of propertynull
public static java.util.Map<java.lang.String,java.lang.String> getSiblings(java.lang.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 java.util.Map<java.lang.String,java.lang.String> getChildren(java.lang.String key)
For example: getChildren("writer")
will return the property writer.level
as level
.
key
- Case-sensitive key of parent propertypublic static void set(java.lang.String key, java.lang.String value) throws java.lang.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 propertyjava.lang.UnsupportedOperationException
- Configuration has already been applied and is frozenpublic static void replace(java.util.Map<java.lang.String,java.lang.String> configuration) throws java.lang.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 configurationjava.lang.UnsupportedOperationException
- Configuration has already been applied and is frozenpublic static java.lang.String resolve(java.lang.String value, org.tinylog.configuration.Resolver resolver)
value
- String with placeholdersresolver
- Resolver for replacing placeholderspublic static void mergeSystemProperties(java.util.Properties properties)
properties
- The properties which the system values shall be merged intopublic static void resolveProperties(java.util.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 © 2022. All rights reserved.