org.javagroups.log
Class Tracer

java.lang.Object
  |
  +--org.javagroups.log.Tracer
Direct Known Subclasses:
NetworkTracer, PrintStreamTracer, SystemTracer, WriterTracer

public abstract class Tracer
extends java.lang.Object

Provides output services for a module. Formats messages by adding a timestamp, the trace level, and the module name. Sends formatted messages to the file, stream, writer, or socket associated with an instance of a concrete subclass of Tracer. Checks trace level and does not send messages if the specified level is less than the trace level set by a call to Trace.setOutput.

Author:
Jim Menard, jimm@io.com
See Also:
Trace

Field Summary
protected  boolean autoFlush
          If true, every call to print will call flush.
protected  boolean closed
          If true, this tracer has been closed and no further output will be accepted.
protected  int level
          The current output trace level.
protected  java.lang.String module
          The module name with which this tracer is associated.
protected static java.lang.String timestampFormat
          Set by Trace.setTimestampFormat() and used in the timestamp method.
 
Method Summary
 void close()
          Flushes any pending output (by calling flush) and closes the output file, stream, writer, or socket associated with this tracer.
protected abstract  void doClose()
          Flushes any pending output (by calling flush) and closes the output file, stream, writer, or socket associated with this tracer.
protected abstract  void doFlush()
          Flushes any pending output.
protected abstract  void doPrint(java.lang.String message)
          Sends the already-formatted message to the output file, stream, writer, or socket associated with this tracer.
 void flush()
          Flushes any pending output.
 boolean getAutoFlush()
          Returns true if this tracer performs auto-flushing after every print.
 int getLevel()
          Returns the current trace level.
 java.lang.String getModule()
          Returns the module name with which this tracer is associated.
protected  java.lang.String logString(java.lang.String module, int level, java.lang.String message)
          Creates a formatted string suitable for output.
protected  java.lang.String logString(java.lang.String module, int level, java.lang.String identifier, java.lang.String message)
           
 void print(java.lang.String module, int level, java.lang.String message)
          Sends a formatted string to the output file, stream, writer, or socket.
 void print(java.lang.String module, int level, java.lang.String identifier, java.lang.String message)
           
 void setAutoFlush(boolean autoFlush)
          Sets the auto-flush flag.
 void setLevel(int level)
          Sets the trace level.
static void setTimestampFormat(java.lang.String format)
          Set the timestamp format.
protected  java.lang.String timestamp()
          Returns a timestamp string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timestampFormat

protected static java.lang.String timestampFormat
Set by Trace.setTimestampFormat() and used in the timestamp method. When null, the default format of ISO 8601 is used.
See Also:
Trace.setTimestampFormat(java.lang.String), Format.formatTimestamp(java.util.Date)

module

protected java.lang.String module
The module name with which this tracer is associated.

level

protected int level
The current output trace level.

autoFlush

protected boolean autoFlush
If true, every call to print will call flush. Initially false.

closed

protected boolean closed
If true, this tracer has been closed and no further output will be accepted.
Method Detail

setTimestampFormat

public static void setTimestampFormat(java.lang.String format)
Set the timestamp format. The format string is that used by SimpleDateFormat. If format is null, then the ISO 8601 date format ("CCYY-MM-DDThh:mm:ss,s") is used.

getModule

public java.lang.String getModule()
Returns the module name with which this tracer is associated.
Returns:
a module name

getLevel

public int getLevel()
Returns the current trace level.
Returns:
the current trace level

setLevel

public void setLevel(int level)
Sets the trace level. Messages sent to this tracer whose level are >= level are output. All others are ignored.
Parameters:
level - the trace level

getAutoFlush

public boolean getAutoFlush()
Returns true if this tracer performs auto-flushing after every print.
Returns:
true if this tracer performs auto-flushing

setAutoFlush

public void setAutoFlush(boolean autoFlush)
Sets the auto-flush flag. If true, every call to print will also call flush.
Parameters:
autoFlush - if true, auto-flushing is turned on

print

public void print(java.lang.String module,
                  int level,
                  java.lang.String message)
Sends a formatted string to the output file, stream, writer, or socket. If level is less than the current trace level, the message is ignored. If autoFlush is true, calls flush.

Calls the abstract method doPrint, which is overridden by concrete subclasses to perform the actual output.

Parameters:
module - a module name
level - a trace level
message - the string to be output

print

public void print(java.lang.String module,
                  int level,
                  java.lang.String identifier,
                  java.lang.String message)

flush

public void flush()
Flushes any pending output.

close

public void close()
Flushes any pending output (by calling flush) and closes the output file, stream, writer, or socket associated with this tracer.

After this method has been called, all calls to print, flush, and close are ignored.


logString

protected java.lang.String logString(java.lang.String module,
                                     int level,
                                     java.lang.String message)
Creates a formatted string suitable for output. The string contains a timestamp, a string version of the trace level, and the module name.
Parameters:
module - a module name
level - a trace level
message - the message to be included
Returns:
a formatted string containing timestamp, level, module name, and message

logString

protected java.lang.String logString(java.lang.String module,
                                     int level,
                                     java.lang.String identifier,
                                     java.lang.String message)

timestamp

protected java.lang.String timestamp()
Returns a timestamp string.
Returns:
an ISO 8601 time string

doPrint

protected abstract void doPrint(java.lang.String message)
Sends the already-formatted message to the output file, stream, writer, or socket associated with this tracer.
Parameters:
message - a formatted string

doFlush

protected abstract void doFlush()
Flushes any pending output. Called from flush, but only if not alread closed.

doClose

protected abstract void doClose()
Flushes any pending output (by calling flush) and closes the output file, stream, writer, or socket associated with this tracer. Called from close, but only if not alread closed.

After closed has been called, all calls to print, flush, and close are ignored.



Copyright © 2001,2002 www.javagroups.com . All Rights Reserved.