edu.stanford.nlp.util.logging
Class OutputHandler

java.lang.Object
  extended by edu.stanford.nlp.util.logging.LogRecordHandler
      extended by edu.stanford.nlp.util.logging.OutputHandler
Direct Known Subclasses:
Redwood.ConsoleHandler, Redwood.FileHandler

public abstract class OutputHandler
extends LogRecordHandler

An abstract handler incorporating the logic of outputing a log message, to some source. This class is responsible for printing channel information, formatting tracks, and writing the actual log messages. Classes overriding this class should implement the print() method based on their output source.

Author:
Gabor Angeli (angeli at cs.stanford)

Field Summary
protected  boolean addRandomColors
           
protected  HashMap<String,Color> channelColors
           
protected  char channelSeparatorChar
          Character used to join multiple channel names
protected  HashMap<String,Style> channelStyles
           
protected  edu.stanford.nlp.util.logging.OutputHandler.TrackInfo info
          The current track info; used to avoid trackStack.peek() calls
protected  int leftMargin
          The length of the left margin in which to print channel information.
protected  int minLineCountForTrackNameReminder
          Number of lines above which the closing brace of a track shows the name of the track
protected  LinkedList<Redwood.Record> queuedTracks
          A list of tracks which have been started but not yet printed as no log messages are in them yet.
protected  String tab
          The tab character
protected  Color trackColor
          The color to use for track beginning and ends
protected  Stack<edu.stanford.nlp.util.logging.OutputHandler.TrackInfo> trackStack
          Information about the current and higher level tracks
protected  Style trackStyle
          The style to use for track beginning and ends
 
Fields inherited from class edu.stanford.nlp.util.logging.LogRecordHandler
EMPTY
 
Constructor Summary
OutputHandler()
           
 
Method Summary
 void colorChannel(String channel, Color color)
          Color the tag for a particular channel this color
 List<Redwood.Record> handle(Redwood.Record record)
          Handle a log Record, either as a filter or by producing a side effect.
abstract  void print(String line)
          Print a string to an output without the trailing newline.
 void setColorChannels(boolean colorChannels)
           
 List<Redwood.Record> signalEndTrack(int newDepth, long timeOfEnd)
          Signal the end of a track, i.e.
 List<Redwood.Record> signalStartTrack(Redwood.Record signal)
          Signal the start of a track, i.e.
protected  StringBuilder style(StringBuilder b, String line, Color color, Style style)
          Style a particular String segment, according to a color and style
 void styleChannel(String channel, Style style)
          Style the tag for a particular channel this style
 
Methods inherited from class edu.stanford.nlp.util.logging.LogRecordHandler
signalShutdown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queuedTracks

protected LinkedList<Redwood.Record> queuedTracks
A list of tracks which have been started but not yet printed as no log messages are in them yet.


trackStack

protected Stack<edu.stanford.nlp.util.logging.OutputHandler.TrackInfo> trackStack
Information about the current and higher level tracks


info

protected edu.stanford.nlp.util.logging.OutputHandler.TrackInfo info
The current track info; used to avoid trackStack.peek() calls


tab

protected String tab
The tab character


channelSeparatorChar

protected char channelSeparatorChar
Character used to join multiple channel names


leftMargin

protected int leftMargin
The length of the left margin in which to print channel information. If this is set to a value < 3, then no channel information is printed.


minLineCountForTrackNameReminder

protected int minLineCountForTrackNameReminder
Number of lines above which the closing brace of a track shows the name of the track


trackColor

protected Color trackColor
The color to use for track beginning and ends


channelColors

protected HashMap<String,Color> channelColors

addRandomColors

protected boolean addRandomColors

trackStyle

protected Style trackStyle
The style to use for track beginning and ends


channelStyles

protected HashMap<String,Style> channelStyles
Constructor Detail

OutputHandler

public OutputHandler()
Method Detail

print

public abstract void print(String line)
Print a string to an output without the trailing newline. Many output handlers can get by with just implementing this method.

Parameters:
line - The string to be printed.

colorChannel

public void colorChannel(String channel,
                         Color color)
Color the tag for a particular channel this color

Parameters:
channel - The channel to color
color - The color to use

styleChannel

public void styleChannel(String channel,
                         Style style)
Style the tag for a particular channel this style

Parameters:
channel - The channel to style
style - The style to use

setColorChannels

public void setColorChannels(boolean colorChannels)

style

protected StringBuilder style(StringBuilder b,
                              String line,
                              Color color,
                              Style style)
Style a particular String segment, according to a color and style

Parameters:
b - The string builder to append to (for efficiency)
line - The String to be wrapped
color - The color to color as
style - The style to use
Returns:
The SringBuilder b

handle

public List<Redwood.Record> handle(Redwood.Record record)
Handle a log Record, either as a filter or by producing a side effect.

Specified by:
handle in class LogRecordHandler
Parameters:
record - The log record to handle
Returns:
a (possibly empty) list of records to be sent on in the pipeline

signalStartTrack

public List<Redwood.Record> signalStartTrack(Redwood.Record signal)
Signal the start of a track, i.e. that we have descended a level deeper.

Overrides:
signalStartTrack in class LogRecordHandler
Parameters:
signal - A record corresponding to the information in the track header. The depth in this object is the old log depth.
Returns:
A list of records to pass down the pipeline, not including the startTrack() signal. The returned records are passed to handle(), not startTrack(), and are sent before the startTrack() signal.

signalEndTrack

public List<Redwood.Record> signalEndTrack(int newDepth,
                                           long timeOfEnd)
Signal the end of a track, i.e. that we have popped up to a higher level.

Overrides:
signalEndTrack in class LogRecordHandler
Parameters:
newDepth - The new depth; that is, the current depth - 1.
Returns:
A list of records to pass down the pipeline. The returned records are passed to handle(), not endTrack(). and are sent before the startTrack() signal.


Stanford NLP Group