|
CSP for Java (JCSP) 1.1-rc4 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jcsp.net.Logger
public 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.
Field Summary | |
---|---|
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. |
Constructor Summary | |
---|---|
Logger(String name,
String defaultDevice)
Creates a new Logger with a given name. |
Method Summary | |
---|---|
static Logger |
getLogger(String name)
Returns a named logger within the system. |
void |
log(Class clazz,
int level,
Object message)
Log a message at the specified level with the specific class. |
void |
log(Class clazz,
Object message)
Log a message with the specific class. |
void |
log(int level,
Object message)
Log a message at a specific level with the default class name. |
void |
log(Object message)
Log a message at the default level with the default class name. |
void |
log(Object object,
int level,
Object message)
Log a message at the specified level with the class of the given object. |
void |
log(Object object,
Object message)
Log a message with the specific class. |
void |
log(String className,
int level,
Object message)
Log a message at the specified level with the specific class name. |
void |
log(String className,
Object message)
Log a message with the specific class. |
void |
setDevice(String device)
Sets the current output device for this logger. |
void |
setLevel(String clazz,
int level)
Sets the current logging level for a given class (and its subclasses). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MAX_LOGGING
public static final int DEFAULT_LOGGING_LEVEL
public static final String DEFAULT_CLASS_NAME
Constructor Detail |
---|
public Logger(String name, String defaultDevice)
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.Method Detail |
---|
public static Logger getLogger(String name)
Returns a named logger within the system. Refer to the constructor for an example of its use.
name
- the name of the logger
InvalidLoggerException
- if the logger specified doesn't exist.public void setDevice(String device)
Sets the current output device for this logger. For example, to suppress infrastructure messages:
Node.info.setDevice (null);
device
- the new device to use.public void setLevel(String clazz, int level)
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.public void log(Object message)
message
- the message to output.public void log(int level, Object message)
level
- the logging level.message
- the message.public void log(String className, int level, Object message)
className
- the class or component name.level
- the logging level.message
- the message.public void log(Class clazz, int level, Object message)
class
- the class generating the message.level
- the logging level.message
- the message.public void log(Object object, int level, Object message)
class
- the object whose class has generated the message.level
- the logging level.message
- the message.public void log(String className, Object message)
class
- the class generating the message.message
- the message.public void log(Class clazz, Object message)
class
- the class generating the message.message
- the message.public void log(Object object, Object message)
class
- the class generating the message.message
- the message.
|
CSP for Java (JCSP) 1.1-rc4 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |