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.
Modifiers | Name | Description |
---|---|---|
static String |
DEFAULT_CLASS_NAME |
The default string if the class name is omitted. |
static int |
DEFAULT_LOGGING_LEVEL |
The default logging level (currently 5) |
static int |
MAX_LOGGING |
The logging level for really important messages. |
Type | Name and description |
---|---|
static Logger |
getLogger(String name) |
void |
log(Object message) Log a message at the default level with the default class name. |
void |
log(int level, Object message) Log a message at a specific level with the default class name. |
void |
log(String className, int level, Object message) Log a message at the specified level with the specific class name. |
void |
log(Class clazz, int level, Object message) Log a message at the specified level with the specific class. |
void |
log(Object object, int level, Object message) Log a message at the specified level with the class of the given object. |
void |
log(String className, Object message) Log a message with the specific class. |
void |
log(Class clazz, Object message) Log a message with the specific class. |
void |
log(Object object, Object message) Log a message with the specific class. |
void |
setDevice(String device) |
void |
setLevel(String clazz, int level) |
The default string if the class name is omitted.
The default logging level (currently 5)
The logging level for really important messages.
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 to System.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:
System.out
.System.err
.If none of these values match it is assumed to be a filename.
name
- the system unique name of the logger.defaultDevice
- the output device to use.
Returns a named logger within the system. Refer to the constructor for an example of its use.
name
- the name of the loggerLog a message at the default level with the default class name.
message
- the message to output.Log a message at a specific level with the default class name.
level
- the logging level.message
- the message.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.
className
- the class or component name.level
- the logging level.message
- the message.Log a message at the specified level with the specific class.
class
- the class generating the message.level
- the logging level.message
- the message.Log a message at the specified level with the class of the given object.
class
- the object whose class has generated the message.level
- the logging level.message
- the message.Log a message with the specific class.
class
- the class generating the message.message
- the message.Log a message with the specific class.
class
- the class generating the message.message
- the message.Log a message with the specific class.
class
- the class generating the message.message
- the message.
Sets the current output device for this logger. For example, to suppress infrastructure messages:
Node.info.setDevice (null);
device
- the new device to use.
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.
clazz
- the name of the class.level
- the maximum level to display.JCSP for Java 1.8 generated 14-10-2016 by Jon Kerridge, Edinburgh Napier University - j dot kerridge at napier dot ac dot uk