Class JulConfig
- java.lang.Object
-
- pl.morgwai.base.logging.JulConfig
-
public class JulConfig extends Object
Utility to overridejava.util.logging
properties with values from system properties.Note: overriding can be applied to an existing java app at run time: just add java-utils jar to the class-path and define desired system properties.
- See Also:
overrideLogLevels(String...)
-
-
Field Summary
Fields Modifier and Type Field Description static String
JUL_CONFIG_CLASS_PROPERTY_NAME
"java.util.logging.config.class"static String
LEVEL_SUFFIX
".level"static String
OVERRIDE_LEVEL_PROPERTY_NAME
Name of the system property that can contain comma separated, fully qualified names ofLogger
s andHandler
s whoseLevel
s will be overridden byoverrideLogLevels(String...)
.
-
Constructor Summary
Constructors Constructor Description JulConfig()
Reads logging config normally and then callsoverrideLogLevels(String...)
.
-
-
-
Field Detail
-
OVERRIDE_LEVEL_PROPERTY_NAME
public static final String OVERRIDE_LEVEL_PROPERTY_NAME
Name of the system property that can contain comma separated, fully qualified names ofLogger
s andHandler
s whoseLevel
s will be overridden byoverrideLogLevels(String...)
.- See Also:
- Constant Field Values
-
LEVEL_SUFFIX
public static final String LEVEL_SUFFIX
".level"- See Also:
- Constant Field Values
-
JUL_CONFIG_CLASS_PROPERTY_NAME
public static final String JUL_CONFIG_CLASS_PROPERTY_NAME
"java.util.logging.config.class"- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JulConfig
public JulConfig() throws Exception
Reads logging config normally and then callsoverrideLogLevels(String...)
. For use with "java.util.logging.config.class" system property.- Throws:
Exception
- See Also:
LogManager
-
-
Method Detail
-
overrideLogLevels
public static void overrideLogLevels(String... names)
OverridesLevel
s ofjava.util.logging
Logger
s andHandler
s with values obtained from system properties.Fully qualified names of
Logger
s andHandler
s whoseLevel
s should be overridden by this method are provided as arguments to this method and/or comma separated on "java.util.logging.overrideLevel" system property.
Name of the system property containing the newLevel
for a givenLogger/Handler
is constructed by appending ".level" to its fully-qualified-name. If a system property with a newLevel
is missing, it is ignored. If it is present, its validity is verified usingLevel.parse(String)
method.Example:
Output all entries fromcom.example
name-space with levelFINE
or higher to the console. Entries from other name-spaces will be logged only if they have at least levelWARNING
, unless configured otherwise in the defaultlogging.properties
file:java -Djava.util.logging.config.class=pl.morgwai.base.logging.JulConfig \ -Djava.util.logging.overrideLevel=,com.example,java.util.logging.ConsoleHandler \ -D.level=WARNING \ -Dcom.example.level=FINE \ -Djava.util.logging.ConsoleHandler.level=FINE \ com.example.someproject.MainClass
-
-