public class Unit
extends net.xqhs.util.config.Config
le(message);
). Logging
primitives will be protected.
It is characterized by the unitName, which also gives the name of the log. If the configured name is
null
, but the instance overrides the getDefaultUnitName()
method, then the value returned
by that method will be used. If the name is null
and there is no override of
getDefaultUnitName()
, no log will be created and the elements in the configuration will be of no effect.
If the name is DEFAULT_UNIT_NAME
, the name of the class will be used. In any other case, the given unit
name will be used and the log name will be computed accordingly -- will be the equal to the unit name or, if
setUnitName(String, boolean, boolean)
is called, the name of the class will be added.
Although not abstract, the Unit cannot be used as a member of a class, as no logging functions are available
publicly. This purpose is fulfilled by UnitComponent
.
Unit
only offers the reduced ('simple') set of primitives specified by the LoggerSimple
interface. It
does not implement the interface however, as that would require the methods to become public.
The class extends Config
, so extending classes can use the features offered by Config
.
The sole purpose of the Unit
layer of an instance is to handle logging.
Modifier and Type | Field and Description |
---|---|
static LoggerSimple.Level |
DEFAULT_LEVEL
The default level for the log, if no other level is set.
|
static java.lang.String |
DEFAULT_UNIT_NAME
The value that should be used to state that the name of the unit should be computed depending on the class name.
|
(package private) DisplayEntity |
display
A
DisplayEntity implementation to which to post logging information. |
(package private) boolean |
ensureNew
If
true , then if another log exists with the same name, an error will be produced. |
(package private) LoggerSimple.Level |
level
The current level of the log.
|
(package private) UnitLinkData |
linkData
Information on linking the behavior of this log to other logs.
|
(package private) net.xqhs.util.logging.logging.LogWrapper |
log
The
LogWrapper that will be used for logging. |
(package private) java.lang.String |
loggerWrapperClass
The class of the logging wrapper that will be used (used only if different from the default types specified by
LogWrapper.LoggerType . |
(package private) net.xqhs.util.logging.logging.LogWrapper.LoggerType |
loggerWrapperType
The type of the logging wrapper that will be used.
|
(package private) java.lang.String |
logName
The name that will be given to the log.
|
(package private) ReportingEntity |
reporter
A
ReportingEntity implementation to which to post logging information. |
(package private) java.lang.String |
unitName
The name of the
Unit . |
Modifier and Type | Method and Description |
---|---|
protected static java.lang.String |
compose(java.lang.String message,
java.lang.Object[] objects)
Composes a message with an array of
Object instances. |
protected void |
dbg(Debug.DebugItem debug,
java.lang.String message,
java.lang.Object... arguments)
This method displays a log message (with the level
TRACE ) only if the specified Debug.DebugItem is
activated. |
protected void |
doExit()
Instructs the Unit to exit.
|
protected java.lang.String |
getDefaultUnitName()
This method is meant to be overridden in inheriting classes, so as to give the default name for units of that
type.
|
protected java.lang.String |
getUnitName()
This method is only accessible inside the instance, except if for good reasons an extending class makes it
public.
|
protected void |
l(LoggerSimple.Level messageLevel,
java.lang.String message,
java.lang.Object... arguments)
This method calls the underlying logging infrastructure to display a message with the specified level, text, and
parameter objects.
|
protected void |
le(java.lang.String message,
java.lang.Object... arguments)
Post an error message.
|
protected void |
lf(java.lang.String message,
java.lang.Object... arguments)
Post a tracing message.
|
protected void |
li(java.lang.String message,
java.lang.Object... arguments)
Post an informative message.
|
Unit |
lock()
Constructs a
Unit according to the previously given parameters. |
boolean |
lockedR()
Calls the
Config.locked() method and if an exception is thrown it posts an error message to the log. |
protected java.lang.Object |
lr(java.lang.Object ret)
This method should be used in return statements.
|
protected java.lang.Object |
lr(java.lang.Object ret,
java.lang.String message,
java.lang.Object... arguments)
This method should be used in return statements.
|
protected void |
lw(java.lang.String message,
java.lang.Object... arguments)
Post a warning message.
|
private java.lang.String |
makeClassName(boolean classNameLong)
Gets the name of the current class, using either the canonical name or the simple name, depending on the
argument.
|
Unit |
setLink(java.lang.String parentLogName)
Sets the name of the parent log.
|
Unit |
setLink(UnitLinkData unitLinkData)
Sets the information on linking this unit to another log.
|
Unit |
setLogDisplay(DisplayEntity logDisplay)
Sets the
DisplayEntity to receive updates form the log. |
Unit |
setLogEnsureNew()
If called, when the log is created, if another log exists with the same name, an error will be produced.
|
Unit |
setLoggerClass(java.lang.String className)
Sets the class of the wrapper for the underlying logger.
|
Unit |
setLoggerType(net.xqhs.util.logging.logging.LogWrapper.LoggerType loggerType)
Sets the type of the logging infrastructure and wrapper used by this unit.
|
protected Unit |
setLoggerTypeClass(net.xqhs.util.logging.logging.LogWrapper.LoggerType loggerType,
java.lang.String className)
Setter for the logger type / logger wrapper class.
|
Unit |
setLogLevel(LoggerSimple.Level logLevel)
Sets the level of the log, as one of
LoggerSimple.Level . |
Unit |
setLogReporter(ReportingEntity reportingEntity)
Sets the
ReportingEntity to receive updates from the log. |
Unit |
setUnitName(java.lang.String name)
Sets the name of the unit (and therefore of the log).
|
Unit |
setUnitName(java.lang.String name,
boolean postfix,
boolean useLongClassName)
Sets the name of the unit (and therefore of the log).
|
private Unit |
setUnitName(java.lang.String name,
boolean addClassName,
boolean postfix,
boolean useLongClassName)
Aggregates parameters from the two other version of the method.
|
public static final java.lang.String DEFAULT_UNIT_NAME
public static final LoggerSimple.Level DEFAULT_LEVEL
java.lang.String unitName
java.lang.String logName
Unit
for details.boolean ensureNew
true
, then if another log exists with the same name, an error will be produced. If
false
and another log with the same name exists, that log will be used.LoggerSimple.Level level
DisplayEntity display
DisplayEntity
implementation to which to post logging information.ReportingEntity reporter
ReportingEntity
implementation to which to post logging information.net.xqhs.util.logging.logging.LogWrapper.LoggerType loggerWrapperType
java.lang.String loggerWrapperClass
LogWrapper.LoggerType
.UnitLinkData linkData
net.xqhs.util.logging.logging.LogWrapper log
LogWrapper
that will be used for logging.public Unit()
Unit
.protected java.lang.String getDefaultUnitName()
Unit
is not dynamic.
This member offers a simpler way to give the default unit name, by reinitializing it. It also offers a simple switch to switch the log level to the default level.
WARNING: making this dynamic (return different values at different times) is useless; the method will be called only when the unit is constructed and the name returned will remain set.
public boolean lockedR()
Config.locked()
method and if an exception is thrown it posts an error message to the log.true
if the configuration was locked, false
otherwise.public Unit lock()
Unit
according to the previously given parameters. More precisely, creates the log,
according to the current configuration.lock
in interface net.xqhs.util.config.Configurable
lock
in class net.xqhs.util.config.Config
public Unit setUnitName(java.lang.String name)
Unit
for details on naming.name
- - the desired name of the unitpublic Unit setUnitName(java.lang.String name, boolean postfix, boolean useLongClassName)
Unit
for details on naming.
In this version of the method, the name of the class will be present in the name of this log, also according to the other parameters.
name
- - the desired name of the unitpostfix
- - if true
, the name of the class will be concatenated after the name of the unit;
otherwise, beforeuseLongClassName
- - if true
, the complete name of the class will be used (including the package).
Otherwise, only the name obtained by Class.getSimpleName()
is used.private Unit setUnitName(java.lang.String name, boolean addClassName, boolean postfix, boolean useLongClassName)
Unit
and the calling methods for
details.name
- - the configured name of the unit.addClassName
- - if true
, the name of this class will be added to the name of the log.postfix
- - if true
, the name of the class will be added after the name of the unit; if
false
, it will be added before.useLongClassName
- - if true
, the canonical name of the class will be used (returned by
getCanonicalName()
; if false, the simple name (returned by getSimpleName()
).private java.lang.String makeClassName(boolean classNameLong)
classNameLong
- - if true
, the canonical name is used; the simple name otherwise.public Unit setLogEnsureNew()
public Unit setLoggerType(net.xqhs.util.logging.logging.LogWrapper.LoggerType loggerType)
loggerType
- - the type of logging infrastructure, as one of LogWrapper.LoggerType
.public Unit setLoggerClass(java.lang.String className)
LogWrapper
.className
- - the name of the class.protected Unit setLoggerTypeClass(net.xqhs.util.logging.logging.LogWrapper.LoggerType loggerType, java.lang.String className)
loggerType
- -- the type of the wrapper, as one of LogWrapper.LoggerType
.className
- -- the class of a LogWrapper
implementation.public Unit setLogLevel(LoggerSimple.Level logLevel)
LoggerSimple.Level
. Messages below this level will not be shown in the output.logLevel
- - the level.public Unit setLink(java.lang.String parentLogName)
parentLogName
- - the name of the parent log.public Unit setLink(UnitLinkData unitLinkData)
unitLinkData
- - the UnitLinkData
instance configuring the link.public Unit setLogDisplay(DisplayEntity logDisplay)
DisplayEntity
to receive updates form the log.logDisplay
- - the display.public Unit setLogReporter(ReportingEntity reportingEntity)
ReportingEntity
to receive updates from the log.reportingEntity
- - the reporter.protected java.lang.String getUnitName()
Unit
name, as given to or set in the constructor.protected void doExit()
As the Unit layer only manages logging, the only thing that happens is that the log exits (if any).
protected void le(java.lang.String message, java.lang.Object... arguments)
LoggerSimple
.message
- : the message to displayarguments
- : arguments to insert into the message. See LoggerSimple
.protected void lw(java.lang.String message, java.lang.Object... arguments)
LoggerSimple
.message
- : the message to displayarguments
- : arguments to insert into the message. See LoggerSimple
.protected void li(java.lang.String message, java.lang.Object... arguments)
LoggerSimple
.message
- : the message to displayarguments
- : arguments to insert into the message. See LoggerSimple
.protected void lf(java.lang.String message, java.lang.Object... arguments)
LoggerSimple
.message
- : the message to displayarguments
- : arguments to insert into the message. See LoggerSimple
.protected java.lang.Object lr(java.lang.Object ret)
Object
in the argument, displaying the Object
. See LoggerSimple
.ret
- : the Object
to return.Object
passed as argument.protected java.lang.Object lr(java.lang.Object ret, java.lang.String message, java.lang.Object... arguments)
Object
in the argument. See LoggerSimple
.
The Object
in the argument is also put in the log message.
ret
- : the Object
to return and to display.message
- : the message to display beside the Object
.arguments
- : arguments to insert into the message. See LoggerSimple
.Object
passed as argument.protected void dbg(Debug.DebugItem debug, java.lang.String message, java.lang.Object... arguments)
TRACE
) only if the specified Debug.DebugItem
is
activated. See LoggerSimple
.debug
- : the Debug.DebugItem
message
- : the log messagearguments
- : arguments to insert into the message. See LoggerSimple
.protected void l(LoggerSimple.Level messageLevel, java.lang.String message, java.lang.Object... arguments)
messageLevel
- - the level of the message.message
- - the text of the message.arguments
- - the objects to be inserted in the placeholders of the message text (see LoggerSimple
).protected static java.lang.String compose(java.lang.String message, java.lang.Object[] objects)
Object
instances. All apparitions of
LoggerSimple.ARGUMENT_PLACEHOLDER
will be replaced with results of calls to the toString()
methods of objects, surrounded by LoggerSimple.ARGUMENT_BEGIN
and LoggerSimple.ARGUMENT_END
.
Remaining objects will be displayed after the message.message
- : the message text.objects
- : the objects.