antlraux package
v0.2.1

antlraux.util
Class Logger

java.lang.Object
  |
  +--antlraux.util.Logger

public class Logger
extends java.lang.Object

This class can be used for maintaining logs. It admits log entries relative to lexical coordinates (a filename, line and column) and non relative entries (no lex info). It also offers other services like tabulation facilities, log count and log deactivation (you can define the minimum level that a message has to have in order to be logged).

Usually you will want to use this class in conjuction with your analizers. In order to do that, you'll have to create your logger and override reportError:

 header{
   import antlraux.util.Logger;
 }

 public class MyParser extends Parser;
 options {...}
 tokens  {...}
 // code zone
 {
    Logger logger = new Logger(...); // add your params here
    public void reportError(RecognitionException re)
    {
       logger.log( re.getMessage(), re.getFileName(),
                   re.getLine(), re.getColumn() );
    }
 }
 
This works more or less the same way for lexers and treeparsers.


Field Summary
protected  antlr.FileLineFormatter flf
          The file line formatter
protected  int logCounter
          Counter
protected  int minLogLevel
          Minimum level of the messages (default -1; shows all messages)
protected  java.lang.String name
          The name of the Logger
protected  java.lang.String newLineString
          String used for new lines
protected  java.io.OutputStream os
          The log's output stream
protected  int tabLevel
          Tabulation level
protected  java.lang.String tabString
          String used in tabulations
 
Constructor Summary
Logger(java.lang.String name)
          Creates a new logger with a certain name
Logger(java.lang.String name, java.io.OutputStream os)
          Specifies name and output stream
Logger(java.lang.String name, java.io.OutputStream os, java.lang.String newLineString, java.lang.String tabString)
          Specifies nearly everything
Logger(java.lang.String name, java.io.OutputStream os, java.lang.String newLineString, java.lang.String tabString, antlr.FileLineFormatter flf)
          Specifies everything
 
Method Summary
 void decTabs()
          Decrements tabLevel by one unit
 antlr.FileLineFormatter getFileLineFormatter()
          Accessor for flf
 int getLogCounter()
          Accessor for logCounter
 int getMinLogLevel()
          Accessor for minLogLevel
 java.lang.String getName()
          Accessor for name
 java.lang.String getNewLineString()
          Accessor for newLineString
 int getTabLevel()
          Accessor for tabLevel
 java.lang.String getTabString()
          Accessor for tabString
 void incTabs()
          Increments tabLevel in one unit
 void log(java.lang.String msg, int msgLevel)
          Adds a log with a certain level.
 void log(java.lang.String msg, int msgLevel, LexInfo li)
          A log with lex info
 void log(java.lang.String msg, int msgLevel, java.lang.String filename, int line, int column)
          A log with lex info
 void newLine()
          Prints the string newLineString once on the Logger's outputStream
 void print(java.lang.String msg)
          Prints a message to the Logger's output stream
 void resetLogCounter()
          Makes logCounter=0
 void setFileLineFormatter(antlr.FileLineFormatter flf)
          Accessor for flf
 void setMinLogLevel(int newMin)
          Accessor for minLogLevel
 void setNewLineString(java.lang.String s)
          Accessor for newLineString
 void setOutputStream(java.io.OutputStream newOs)
          Accessor for os
 void setTabLevel(int t)
          Accessor for tabLevel.
 void setTabString(java.lang.String ts)
          Accessor for tabString
 void tabulate()
          Prints the string "tabString" tabLevel times on the Logger's outputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tabLevel

protected int tabLevel
Tabulation level


minLogLevel

protected int minLogLevel
Minimum level of the messages (default -1; shows all messages)


logCounter

protected int logCounter
Counter


name

protected java.lang.String name
The name of the Logger


tabString

protected java.lang.String tabString
String used in tabulations


newLineString

protected java.lang.String newLineString
String used for new lines


flf

protected antlr.FileLineFormatter flf
The file line formatter


os

protected java.io.OutputStream os
The log's output stream

Constructor Detail

Logger

public Logger(java.lang.String name)
Creates a new logger with a certain name


Logger

public Logger(java.lang.String name,
              java.io.OutputStream os)
Specifies name and output stream


Logger

public Logger(java.lang.String name,
              java.io.OutputStream os,
              java.lang.String newLineString,
              java.lang.String tabString)
Specifies nearly everything


Logger

public Logger(java.lang.String name,
              java.io.OutputStream os,
              java.lang.String newLineString,
              java.lang.String tabString,
              antlr.FileLineFormatter flf)
Specifies everything

Method Detail

print

public void print(java.lang.String msg)
Prints a message to the Logger's output stream


log

public void log(java.lang.String msg,
                int msgLevel)
Adds a log with a certain level. This log will only be processed if msgLevel>minLogLevel. If the log is processed, logCounter is incremented.


log

public void log(java.lang.String msg,
                int msgLevel,
                java.lang.String filename,
                int line,
                int column)
A log with lex info


log

public void log(java.lang.String msg,
                int msgLevel,
                LexInfo li)
A log with lex info


tabulate

public void tabulate()
Prints the string "tabString" tabLevel times on the Logger's outputStream.


newLine

public void newLine()
Prints the string newLineString once on the Logger's outputStream


incTabs

public void incTabs()
Increments tabLevel in one unit


decTabs

public void decTabs()
Decrements tabLevel by one unit


getLogCounter

public int getLogCounter()
Accessor for logCounter


resetLogCounter

public void resetLogCounter()
Makes logCounter=0


getName

public java.lang.String getName()
Accessor for name


getMinLogLevel

public int getMinLogLevel()
Accessor for minLogLevel


setMinLogLevel

public void setMinLogLevel(int newMin)
Accessor for minLogLevel


getTabLevel

public int getTabLevel()
Accessor for tabLevel


setTabLevel

public void setTabLevel(int t)
Accessor for tabLevel. You should use incTabs() and decTabs() instead of this method whenever possible.


getTabString

public java.lang.String getTabString()
Accessor for tabString


setTabString

public void setTabString(java.lang.String ts)
Accessor for tabString


getNewLineString

public java.lang.String getNewLineString()
Accessor for newLineString


setNewLineString

public void setNewLineString(java.lang.String s)
Accessor for newLineString


getFileLineFormatter

public antlr.FileLineFormatter getFileLineFormatter()
Accessor for flf


setFileLineFormatter

public void setFileLineFormatter(antlr.FileLineFormatter flf)
Accessor for flf


setOutputStream

public void setOutputStream(java.io.OutputStream newOs)
Accessor for os


antlraux package
v0.2.1

Created by Enrique José García Cota