Document |
xxxx |
Authors |
J. L. Abad Peiro (ZRL)
|
Editor |
C. Gulcu (ZRL) |
Status |
Alpha Version 0.7, SEMPER internal |
The semper.util.log package exports only a single class namely Log, although it defines two other unexported classes for internal use.
The goal of the LOG package is to provide a general but simple, yet robust and flexible logging facility. A major objective is to minimize source code fiddling in order to activate/deactivate arbitrary log messages. Ideally, one should be able to write a log statement in the source code and control its activation/deactivation dynamically through some sort of preference manager.
We write bytes instaed of unicode chars... (Mehdi's suggestion)
The LOG package requires the ExecInfo class defined in the "semper.util.execInfo" package. The ExecInfo class is used to print stack tracing information.
The TINGUIN and Preferences packages are required too.
Corresponds to highly irrecuperable malfunctions. CRITICAL level errors should be used for extremely serious error conditions.
Corresponds to serious malfunction. ERROR level errors should be used for highly serious error conditions.
Corresponds to situations of minor malfunction or misconfiguration. WARNING level messages should be used for situations reflecting misconfigurations or probable programming errors.
Corresponds to progress report messages. INFO level is intended for high level messages, e.g. for reporting to the user/programmer on the progress of a particular run.
Corresponds to debugging messages. TRACE level is intended for use in isolating programming erros.
Don't use this method anymore. There is no need for it.
This form is provided for compatibility with existing code. On Asokans request, it adds ".log" to the file name parameter.
Log.loadPrefs() reads the saved settings from disk and overwrites the actual values. This method need a initialised Preferences.class.
The Log.log() method may send a message to [LogFile] depending on the space separated categoryList and level parameters.
The categoryList parameter specifies a list of categories. Each element of this list corresponds to a specific category to which the log message belongs.
A message can belong to multiple categories.
For example the code
Log.log("X.CONTRUCTOR PAYMENT", Log.TRACE, "Some message");specifies that "Some Message" belongs to the "X.CONSTRUCTOR" and "PAYMENT" categories and is of level Log.TRACE.
The category values are set in the preference manager. The allowed values are (in increasing priority) CRITICAL, ERROR, WARNING, INFO and TRACE.
When a message belongs to more than one category the category with the lowest priority dominates. We say that lower severity messages subsume higher severity messages. The rationale behind this is that, if you are interested in lower severity messages then you are certainly interested in more severe messages. If a message does not belong to a known category, it is assigned a default category level as specified by the [DefaultCategoryLevel] option.
For example, if we set
DefaultCategoryLevel = TRACE X = INFO Y = WARNINGthen, in the code
Log.log("X Y", Log.TRACE, "Message 2"); // X dominates Log.log("Z", Log.TRACE, "Message 2"); // Z is not set"X Y" evaluates to INFO and Z evaluates to TRACE.
Once the categoryList parameter is evaluated it is compared with the actual level of the message. If the valuation of categoryList subsumes the level parameter, then the message is logged.
For example, if we set
DefaultCategoryLevel = TRACE X = INFO Y = WARNINGthen,
Log.Trace("X" , "Message 1");will not log, since X doesn't subsume TRACE. Similarly,
Log.Error("X Y", "Message 2");will log, since "X Y" evaluates to INFO and INFO subsumes ERROR. Remark: The order in which the categories are listed is insignificant.
By convention, a if a message pertains to a certain category it also pertains to all dot separated prefixes of that category. For example,
Log.trace("X.Y.Z", "Some message");means that "Some message" pertains to categories "X.Y.Z", "X.Y" and "X".
When evaluating categories the most specific category has precedence. For example, if in the preferences manager we set
X = TRACE X.Y = INFO X.Y.Z = WARNINGthen, in the code
Log.trace("X.Y.Z", "Some message");"X.Y.Z" will evaluate to WARNING. Furthermore, since WARNING does not subsume TRACE the message will not log.
Similarly,
Log.trace("X.Y.WHATEVER", "Some message");will evaluate to the value of X.Y ("INFO") assuming X.Y.WHATEVER is unset. Consequently, the message will not log.
Similar to the preceding log() form except that the category is derived from the class name of the specified object,
This form is provided for compatibility with existing code. It should be phased out.
Similar to log() except that the message level is deduced from the method name itself.
These new forms are provided as a syntaxic facility.
Set the log file where logging messages will go. Equivalent to setting up the [LogFile] option in the preference manager. If unset, there is no default value is an empty String. This method does not save the change to disk.
Sets up the default level assigned to unknown categories. Equivalent to setting up the [DefaultCategoryLevel] option in the preference manager. If unset, the default category level is INFO. This method does not save the change to disk.
Configure loging categories. This method does not save the change to disk.
Configure loging categories. This method does not save the change to disk.
Set the stack information threshold. Equivalent to setting up the [StackInfoThreshold] option in the preference manager. If unset, defaults to WARNING. This method does not save the change to disk.
Stack tracing information is added for all messages of same or higher severity than the stack information threshold.
Sets whether date printing is enabled or not. Equivalent to setting up the [DatePrinting] option in the preference manager. If unset, defaults to TRUE. This method does not save the change to disk.
If date printing is enabled, then date information is added to all logged messages.Sets whether date printing is enabled or not. Equivalent to setting up the [TimePrinting] option in the preference manager. If unset, defaults to TRUE. This method does not save the change to disk.
If time printing is enabled, then time information is added to all logged messages.Sets whether thread printing is enabled or not. Equivalent to setting up the [ThreadPrinting] option in the preference manager. If unset, defaults to TRUE. This method does not save the change to disk.
If thread printing is enabled, then the name of the current thread is added to all logged messages.Set whether category printing is enabled or not.
If time category printing is enabled, then the first category in the categoryList (see log() ) is added to all messages. This method does not save the change to disk.
Set the standard prefix added to all messages. Returns the old standard prefix. This method does not save the change to disk.
if saveit is true, the change will be saved to disk.
If this flag is set, all SetX-methods have no effect. The user might dislike that a program changes his saved settings. In this case the user can set this flag.
The name of the file where messages are appended. There default
is an empty string. Possible values (in decreasing severity) are CRITICAL, ERROR,
WARNING, INFO and TRACE.
Default value is ERROR.
The default level for unknown categories. Possible values (in decreasing priority) are CRITICAL, ERROR,
WARNING, INFO and TRACE.
Default value is ERROR.
Additional stacked information is recorded with the logged message
if its level has the same or higher priority than [StackInfoThreshold].
Possible values are TRUE and FALSE. Default value is TRUE. If the
[TimePrinting] is set to TRUE then all messages are prefixed with the
current time (see logging format below). Possible values are TRUE and FALSE. Default value is TRUE. Similar to
the [TimePrinting] option (see logging format below).
Possible values are TRUE and FALSE. Default value is TRUE. If
[ThreadPrinting] is set to true, then the name of the current thread
is appended to the log file, (see logging format
below).
All strings are valid. Log messages are prefixed with the log
prefix (see logging format below). By default
the [LogPrefix] is set to null value.
Possible values are TRUE and FALSE. Default is TRUE. If
CategoryPrefixing is enabled then the first listed category
in the log() method's first argument, i.e. categoryList, is prepended
to the message.
The logging format is:
{} means that the field is optional. The date is in the European format where the day
precedes the month. Months are represented by their 3 letter
abbreviations, i.e. Jan, Feb, ..., Dec.
For example, if in the preference manager we set
[LogFile]
[DefaultCategoryLevel]
[StackInfoThreshold]
[TimePrinting]
[DatePrinting]
[ThreadPrinting]
[LogPrefix]
[CategoryPrefixing]
Logging format
{date} {time} LEVEL {threadName} {StdPrefix} {CategoryPrefix} - logMessage
DefaultCategoryLevel = INFO
StackInfoThreshold = WARNING
DatePrinting = TRUE
TimePrinting = TRUE
ThreadPinting = TRUE
StdPrefix = Semper
CategoryPrefixing = TRUE
SEMPER = INFO
then,
Log.critical("X", "Some critical message");
Log.info("SEMPER.PAYMENT TINGUIN", "Some info message");
will log
[14:02:08] 07Aug1996 CRITICAL [main] Semper X - Some critical message
at semper.util.log.Test.Test.x(Test.java:55)
at semper.util.log.Test.Test.main(Test.java:52)
[14:02:31] 07Aug1996 INFO [main] Semper SEMPER.PAYMENT - Some info message