Class Logger
Manages the output of diagnostic messages to one or more devices. Instances of this class represent
a log output device to which diagnostic or error messages can be written. The instance can be tied to
an actual device such as a file or the standard I/O streams provided by the System
class.
All messages must be signed by an application class and may also contain a severity level. The higher the number the less severe the problem. The output generated can be controlled by setting the maximum level that should be reported. Thus, essential output should be written at level 1. Less severe and verbose output should be written at higher levels depending on the granularity of information required when testing a program.
The default logging level is 5. That is, for all classes only messages up to level 5 by default will be displayed.
Messages from the infrastructure classes are written to the loggers Node.info
and
Node.err
which are by default connected to System.out
and System.in
respectively.
Alternative implementations of this class may instead write to a system event log or format the information in manners tailored to particular debugging environments.
- Author:
- Quickstone Technologies Limited
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The default string if the class name is omitted.static final int
The default logging level (currently 5)static final int
The logging level for really important messages. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Logger
Returns a named logger within the system.void
Log a message at a specific level with the default class name.void
Log a message at the specified level with the specific class.void
Log a message with the specific class.void
Log a message at the default level with the default class name.void
Log a message at the specified level with the class of the given object.void
Log a message with the specific class.void
Log a message at the specified level with the specific class name.void
Log a message with the specific class.void
Sets the current output device for this logger.void
Sets the current logging level for a given class (and its subclasses).
-
Field Details
-
MAX_LOGGING
public static final int MAX_LOGGINGThe logging level for really important messages.- See Also:
-
DEFAULT_LOGGING_LEVEL
public static final int DEFAULT_LOGGING_LEVELThe default logging level (currently 5)- See Also:
-
DEFAULT_CLASS_NAME
The default string if the class name is omitted.- See Also:
-
-
Constructor Details
-
Logger
Creates a new
Logger
with a given name. The name assigned is arbitrary but allows the logger to be uniquely identified by name. For example instead of assigning a static reference somewhere to always refer to a logger, one can be named and resolved dynamically:public static void main (String[] args) { new Logger ("errors", "stderr"); }
This will allocate a logger with the name
errors
connected toSystem.err
. Elsewhere in the program one can write:Logger.getLogger ("errors")
To obtain a reference to this logger.
The default device can take one of three reserved values:
- null - no output device; all logged events are discarded.
- stdout - write to
System.out
. - stderr - write to
System.err
.
If none of these values match it is assumed to be a filename.
- Parameters:
name
- the system unique name of the logger.defaultDevice
- the output device to use.
-
-
Method Details
-
getLogger
Returns a named logger within the system. Refer to the constructor for an example of its use.
- Parameters:
name
- the name of the logger- Returns:
- the logger
- Throws:
org.jcsp.net.Logger.InvalidLoggerException
- if the logger specified doesn't exist.
-
setDevice
Sets the current output device for this logger. For example, to suppress infrastructure messages:
Node.info.setDevice (null);
- Parameters:
device
- the new device to use.
-
setLevel
Sets the current logging level for a given class (and its subclasses). Only messages generated by that class (or its subclasses) with a lesser level will be output.
- Parameters:
clazz
- the name of the class.level
- the maximum level to display.
-
log
Log a message at the default level with the default class name.- Parameters:
message
- the message to output.
-
log
Log a message at a specific level with the default class name.- Parameters:
level
- the logging level.message
- the message.
-
log
Log a message at the specified level with the specific class name. Note that this does not have to match a real class name so could be used to describe the subsystem generating the message more meaningfully.- Parameters:
className
- the class or component name.level
- the logging level.message
- the message.
-
log
Log a message at the specified level with the specific class.- Parameters:
level
- the logging level.message
- the message.class
- the class generating the message.
-
log
Log a message at the specified level with the class of the given object.- Parameters:
level
- the logging level.message
- the message.class
- the object whose class has generated the message.
-
log
Log a message with the specific class.- Parameters:
message
- the message.class
- the class generating the message.
-
log
Log a message with the specific class.- Parameters:
message
- the message.class
- the class generating the message.
-
log
Log a message with the specific class.- Parameters:
message
- the message.class
- the class generating the message.
-