Package diva.util
Class LoggableOp
- java.lang.Object
-
- diva.util.LoggableOp
-
public class LoggableOp extends java.lang.Object
This is an abstract base class for objects that need to log error or warning messages. It is useful for things like parsers and printers -- anything that need to perform a complex operation but might encounter errors that need to be displayed to the user.- Version:
- $Id$
- Author:
- John Reekie
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
_verbose
If true, then print extra information in the error output.
-
Constructor Summary
Constructors Constructor Description LoggableOp()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getErrorCount()
Get the number of errors generated during the most recent operation.java.io.PrintStream
getErrorStream()
Get the stream to which errors are printed.int
getLineNumber()
Get the current line number.int
getWarningCount()
Get the number of warnings generated during the most recent parse.void
indent()
Increment the indentation counter.boolean
isVerbose()
Test if we are in verbose mode.void
logError(java.lang.String msg)
Print an error message to the error stream.void
logError(java.lang.String id, java.lang.String msg)
Print an error message to the error stream.void
logError(java.lang.String id, java.lang.String msg, java.lang.String detail)
Print an error message to the error stream.void
logInfo(java.lang.String msg)
If in verbose mode, print an info message to the error stream, otherwise do nothing.void
logInfo(java.lang.String id, java.lang.String msg)
If in verbose mode, print an info message to the error stream, otherwise do nothing.void
logWarning(java.lang.String msg)
Print an warning message to the error stream.void
logWarning(java.lang.String id, java.lang.String msg)
Print an warning message to the error stream.void
logWarning(java.lang.String id, java.lang.String msg, java.lang.String detail)
Print an warning message to the error stream.void
reset()
Reset the error counters.void
setErrorStream(java.io.PrintStream err)
Set the stream to which errors are printed.void
setVerbose(boolean v)
Set the verbose mode flag.void
unindent()
Decrement the indentation counter.
-
-
-
Method Detail
-
getErrorCount
public int getErrorCount()
Get the number of errors generated during the most recent operation.- Returns:
- The number of errors
-
getErrorStream
public java.io.PrintStream getErrorStream()
Get the stream to which errors are printed.- Returns:
- The error stream
- See Also:
setErrorStream(PrintStream)
-
getWarningCount
public int getWarningCount()
Get the number of warnings generated during the most recent parse.- Returns:
- The warning count
-
getLineNumber
public int getLineNumber()
Get the current line number. Subclasses should override if they know about line numbers. The default implementation returns -1, which means that line numbers are not understood.- Returns:
- The line number. In this base class, return -1.
-
logError
public void logError(java.lang.String msg)
Print an error message to the error stream. This message includes the line number, and info message.- Parameters:
msg
- The message
-
logError
public void logError(java.lang.String id, java.lang.String msg)
Print an error message to the error stream. This prints the error id, line number, and info message.- Parameters:
id
- The error idmsg
- The info message
-
logError
public void logError(java.lang.String id, java.lang.String msg, java.lang.String detail)
Print an error message to the error stream. This prints the error id, line number, info message. On a second line, it prints the detail information.- Parameters:
id
- The error idmsg
- The infor messagedetail
- The detail information
-
logInfo
public void logInfo(java.lang.String msg)
If in verbose mode, print an info message to the error stream, otherwise do nothing. This message includes the line number, and info message. The output is indented by the current indentation amount, allowing recursive operations to be printed more clearly.- Parameters:
msg
- The info message
-
logInfo
public void logInfo(java.lang.String id, java.lang.String msg)
If in verbose mode, print an info message to the error stream, otherwise do nothing. This prints the info id, line number, and info message. The output is indented by the current indentation amount, allowing recursive operations to be printed more clearly.- Parameters:
id
- The error idmsg
- The info message
-
indent
public void indent()
Increment the indentation counter.
-
isVerbose
public final boolean isVerbose()
Test if we are in verbose mode.- Returns:
- True if we are in verbose mode
- See Also:
setVerbose(boolean)
-
reset
public void reset()
Reset the error counters.
-
setErrorStream
public void setErrorStream(java.io.PrintStream err)
Set the stream to which errors are printed. The default error stream is System.err.- Parameters:
err
- The stream- See Also:
getErrorStream()
-
setVerbose
public void setVerbose(boolean v)
Set the verbose mode flag. In verbose mode, calls to the logInfo() method write to the error output.- Parameters:
v
- True if we are in verbose mode.- See Also:
isVerbose()
-
unindent
public void unindent()
Decrement the indentation counter.
-
logWarning
public void logWarning(java.lang.String msg)
Print an warning message to the error stream. This message includes the line number, and info message.- Parameters:
msg
- The warning message
-
logWarning
public void logWarning(java.lang.String id, java.lang.String msg)
Print an warning message to the error stream. This prints the warning id, line number, and info message.- Parameters:
id
- The warning idmsg
- The warning message
-
logWarning
public void logWarning(java.lang.String id, java.lang.String msg, java.lang.String detail)
Print an warning message to the error stream. This prints the warning id, line number, info message. On a second line, it prints the detail information.- Parameters:
id
- The warning idmsg
- The warning messagedetail
- The detail message
-
-