de.unkrig.commons.util.logging
Class LogUtil

java.lang.Object
  extended by de.unkrig.commons.util.logging.LogUtil

public final class LogUtil
extends java.lang.Object

Various java.util.logging-related utility methods.


Field Summary
static java.util.logging.Level INFO_PLUS_1
          A Level one higher (towards Level.WARNING) than Level.INFO.
static java.util.logging.Filter LESS_THAN_CONFIG
          Regards levels less than Level.CONFIG (e.g.
static java.util.logging.Filter LESS_THAN_INFO
          Regards levels less than Level.INFO (e.g.
static java.util.logging.Filter LESS_THAN_WARNING
          Regards levels less than Level.WARNING (e.g.
static java.util.logging.LogManager LOG_MANAGER
          An alternative to repeated calls to LogManager.getLogManager().
static java.util.logging.Logger ROOT_LOGGER
          Is Logger.getLogger("").
static java.util.logging.Level WARNING_PLUS_1
          A Level one higher (towards Level.SEVERE) than Level.WARNING.
 
Method Summary
static java.lang.Boolean getLoggingProperty(java.lang.String propertyName, java.lang.Boolean defaulT)
           
static
<T> T
getLoggingProperty(java.lang.String propertyName, java.lang.Class<T> type)
          Evaluates the value of the named property to an object of the given type and returns it.
static
<T> T
getLoggingProperty(java.lang.String propertyName, java.lang.Class<T> type, T defaulT)
          Evaluates the value of the named property to an object of the given type and returns it, or the defaulT.
static java.util.logging.Level getLoggingProperty(java.lang.String propertyName, java.util.logging.Level defaulT)
           
static long getLoggingProperty(java.lang.String propertyName, java.lang.Long defaulT)
           
static java.lang.String getLoggingProperty(java.lang.String propertyName, java.lang.String defaulT)
           
static java.util.logging.Filter levelLimitFilter(java.util.logging.Level upperBound)
           
static Consumer<java.lang.String> logConsumer(java.util.logging.Logger logger, java.util.logging.Level level, java.lang.String prefix)
          Strings passed to the returned Consumer are logged to the given logger at the given level.
static java.io.Writer logWriter(java.util.logging.Logger logger, java.util.logging.Level level, java.lang.String prefix)
          Lines written to the returned Writer are optionally prepended with the given prefix, and then logged to the given Logger at the given Level.
static Expression parseLoggingProperty(java.lang.String propertyName, Predicate<java.lang.String> isValidVariableNames)
          Parses an expression from the value of the named logging property.
static java.lang.String requireLoggingProperty(java.lang.String propertyName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_MANAGER

public static final java.util.logging.LogManager LOG_MANAGER
An alternative to repeated calls to LogManager.getLogManager().


ROOT_LOGGER

public static final java.util.logging.Logger ROOT_LOGGER
Is Logger.getLogger("").


WARNING_PLUS_1

public static final java.util.logging.Level WARNING_PLUS_1
A Level one higher (towards Level.SEVERE) than Level.WARNING.


INFO_PLUS_1

public static final java.util.logging.Level INFO_PLUS_1
A Level one higher (towards Level.WARNING) than Level.INFO.


LESS_THAN_WARNING

public static final java.util.logging.Filter LESS_THAN_WARNING
Regards levels less than Level.WARNING (e.g. INFO, CONFIG, FINE, FINER, FINEST) as loggable.


LESS_THAN_INFO

public static final java.util.logging.Filter LESS_THAN_INFO
Regards levels less than Level.INFO (e.g. CONFIG, FINE, FINER, FINEST) as loggable.


LESS_THAN_CONFIG

public static final java.util.logging.Filter LESS_THAN_CONFIG
Regards levels less than Level.CONFIG (e.g. FINE, FINER, FINEST) as loggable.

Method Detail

logConsumer

public static Consumer<java.lang.String> logConsumer(java.util.logging.Logger logger,
                                                     java.util.logging.Level level,
                                                     @Nullable
                                                     java.lang.String prefix)
Strings passed to the returned Consumer are logged to the given logger at the given level.

Parameters:
prefix - Is prepended to each string before it is logged

logWriter

public static java.io.Writer logWriter(java.util.logging.Logger logger,
                                       java.util.logging.Level level,
                                       @Nullable
                                       java.lang.String prefix)
Lines written to the returned Writer are optionally prepended with the given prefix, and then logged to the given Logger at the given Level.


levelLimitFilter

public static java.util.logging.Filter levelLimitFilter(java.util.logging.Level upperBound)
Returns:
A Filter that regards levels lower than upperBound as loggable

getLoggingProperty

public static java.lang.Boolean getLoggingProperty(java.lang.String propertyName,
                                                   java.lang.Boolean defaulT)
Returns:
The boolean value of the named logging property, or the defaulT

getLoggingProperty

public static <T> T getLoggingProperty(java.lang.String propertyName,
                                       java.lang.Class<T> type)
                            throws ParseException,
                                   EvaluationException
Evaluates the value of the named property to an object of the given type and returns it.

Throws:
java.lang.IllegalArgumentException - The logging property is not defined
EvaluationException - The property evaluates to null
EvaluationException - The value of the property is not assignable to T
ParseException

getLoggingProperty

@Nullable
public static <T> T getLoggingProperty(java.lang.String propertyName,
                                                java.lang.Class<T> type,
                                                @Nullable
                                                T defaulT)
                            throws ParseException,
                                   EvaluationException
Evaluates the value of the named property to an object of the given type and returns it, or the defaulT.

Throws:
ParseException
EvaluationException
See Also:
ExpressionEvaluator.evaluateTo(String, de.unkrig.commons.lang.protocol.Mapping, Class)

getLoggingProperty

public static java.util.logging.Level getLoggingProperty(java.lang.String propertyName,
                                                         java.util.logging.Level defaulT)
Returns:
The level value of the named logging property, or the given defaulT
Throws:
java.lang.IllegalArgumentException - The value could not be parsed to a valid level

getLoggingProperty

public static long getLoggingProperty(java.lang.String propertyName,
                                      java.lang.Long defaulT)
Returns:
The value of the named logging property, converted to LONG, or the defaulT
Throws:
java.lang.IllegalArgumentException - The property text cannot be parsed into a LONG

getLoggingProperty

@Nullable
public static java.lang.String getLoggingProperty(java.lang.String propertyName,
                                                           @Nullable
                                                           java.lang.String defaulT)
Returns:
The value of the named logging property, or the defaulT

requireLoggingProperty

public static java.lang.String requireLoggingProperty(java.lang.String propertyName)
Returns:
The value of the named logging property
Throws:
java.lang.IllegalArgumentException - The named logging property is not defined

parseLoggingProperty

public static Expression parseLoggingProperty(java.lang.String propertyName,
                                              Predicate<java.lang.String> isValidVariableNames)
                                       throws ParseException
Parses an expression from the value of the named logging property.

Throws:
java.lang.IllegalArgumentException - The named logging property is not defined
ParseException