ec.util
Class Output

java.lang.Object
  extended by ec.util.Output
All Implemented Interfaces:
IOutput, java.io.Serializable

public class Output
extends java.lang.Object
implements IOutput

Outputs and logs system messages, errors, and other various items printed as a result of a run.

Output maintains zero or more logs, which contain Writers which write out stuff. Each log has an associated verbosity; if request is made to write text to a log, and the text's maximal verbosity is lower than the verbosity of the log, the log will not write it. Each Output instance also has an instance-level global verbosity; incoming requests to write text are additionally subject to this verbosity test. Lastly, the Output class itself has a global verbosity as well. This last verbostity is useful for shutting down writing to all logs in the entire system in a simple way.

When the system fails for some reason and must be started back up from a checkpoint, Output's log files may be overwritten. Output offers three approaches here. First, Output can clear the log file and overwrite it. Second, Output can append to the existing log file; because checkpoints are only done occasionally, this may result in duplicate outputs to a file, so keep this in mind. Third, Output can keep certain written text, typically announcements, in memory; this text gets written out into the checkpoint file, and so it is sound.

There are several kinds of announcements, in different levels of importance.

  1. SYSTEM MESSAGEs. Useful system-level facts printed out for the benefit of the user.
  2. FATAL ERRORs. These errors cause the system to exit(1) immediately.
  3. Simple ERRORs. These errors set the "errors" flag to true; at the end of a stream of simple errors, the system in general is expected to exit with a fatal error due to the flag being set. That's the protocol anyway. On restart from a checkpoint, if there were any simple errors, the system ends with a fatal error automatically.
  4. WARNINGs. These errors do not cause the system to exit under any circumstances.
  5. MESSAGEs. Useful facts printed out for the benefit of the user.

The default verbosity values for different kinds of announcements are given below:

0V_VERBOSE(totally verbose)
1000V_NO_MESSAGES(don't print messages or system messages)
2000V_NO_WARNINGS(don't print warnings, messages or system messages)
3000V_NO_GENERAL(don't print warnings, messages, system messages, or other "general info" stuff that might come along (like statistics maybe))
4000V_NO_ERRORS(don't even print errors)
5000V_TOTALLY_SILENT(be totally silent)

Version:
1.0
Author:
Sean Luke
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface ec.util.IOutput
ALL_LOGS, V_NO_ERRORS, V_NO_GENERAL, V_NO_MESSAGES, V_NO_WARNINGS, V_TOTALLY_SILENT, V_VERBOSE
 
Constructor Summary
Output(boolean storeAnnouncementsInMemory, int _verbosity)
          Creates a new, verbose, empty Output object.
 
Method Summary
 int addLog(java.io.File filename, int _verbosity, boolean postAnnouncements, boolean appendOnRestart)
          Creates a new log of minimal verbosity verbosity and adds it to Output.
 int addLog(java.io.File filename, int _verbosity, boolean postAnnouncements, boolean appendOnRestart, boolean gzip)
          Creates a new log of minimal verbosity verbosity and adds it to Output.
 int addLog(int descriptor, int _verbosity, boolean postAnnouncements)
          Creates a new log of minimal verbosity verbosity and adds it to Output.
 int addLog(Log l)
           
 int addLog(java.io.Writer writer, LogRestarter restarter, int _verbosity, boolean postAnnouncements, boolean repostAnnouncements)
           
 void clearAnnouncements()
          Clears out announcements.
 void clearErrors()
          Clears the error flag.
 void close()
          Closes the logs -- ONLY call this if you are preparing to quit
 void error(java.lang.String s)
          Posts a simple error.
 void error(java.lang.String s, Parameter p1)
          Posts a simple error.
 void error(java.lang.String s, Parameter p1, Parameter p2)
          Posts a simple error.
 void exitIfErrors()
          Exits with a fatal error if the error flag has been raised.
 void fatal(java.lang.String s)
          Posts a fatal error.
 void fatal(java.lang.String s, Parameter p1)
          Posts a fatal error.
 void fatal(java.lang.String s, Parameter p1, Parameter p2)
          Posts a fatal error.
protected  void finalize()
           
 void flush()
          Flushes the logs
 int getVerbosity()
          Returns the Output object's general verbosity
static void initialError(java.lang.String s)
          Prints an initial error to System.err.
static void initialError(java.lang.String s, Parameter p1)
          Prints an initial error to System.err.
static void initialError(java.lang.String s, Parameter p1, Parameter p2)
          Prints an initial error to System.err.
 Log log(int x)
           
 void message(java.lang.String s)
          Posts a message.
 int numLogs()
           
 void print(java.lang.String s, int _verbosity, int log)
          Prints a non-announcement message to a given log, with a certain verbosity.
 void print(java.lang.String s, int _verbosity, int[] _logs)
          Prints a non-announcement message to the given logs, with a certain verbosity.
protected  void print(java.lang.String s, int _verbosity, Log log)
          Prints a non-announcement message to a given log, with a certain verbosity.
 void println(java.lang.String s, int _verbosity, int log)
          Prints a non-announcement message to the given logs, with a certain verbosity.
 void println(java.lang.String s, int _verbosity, int[] _logs)
          Prints a non-announcement message to the given logs, with a certain verbosity.
 void println(java.lang.String s, int _verbosity, int log, boolean _announcement)
          Prints a message to a given log, with a certain verbosity.
protected  void println(java.lang.String s, int _verbosity, Log log, boolean _announcement, boolean _reposting)
          Prints a message to a given log, with a certain verbosity.
 Log removeLog(int x)
           
 void reopen(int _log)
           
 void reopen(int[] _logs)
           
 void restart()
           
 void setFilePrefix(java.lang.String filePrefix)
           
 boolean setFlush(boolean v)
          Sets whether the Output flushes its announcements.
 int setVerbosity(int v)
          Sets the Output object's general verbosity to v.
 void systemMessage(java.lang.String s)
          Posts a system message.
 void warning(java.lang.String s)
          Posts a warning.
 void warning(java.lang.String s, Parameter p1)
          Posts a warning.
 void warning(java.lang.String s, Parameter p1, Parameter p2)
          Posts a warning.
 void warnOnce(java.lang.String s)
          Posts a warning one time only.
 void warnOnce(java.lang.String s, Parameter p1)
           
 void warnOnce(java.lang.String s, Parameter p1, Parameter p2)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Output

public Output(boolean storeAnnouncementsInMemory,
              int _verbosity)
Creates a new, verbose, empty Output object.

Method Detail

setFilePrefix

public void setFilePrefix(java.lang.String filePrefix)
Specified by:
setFilePrefix in interface IOutput

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

close

public void close()
Description copied from interface: IOutput
Closes the logs -- ONLY call this if you are preparing to quit

Specified by:
close in interface IOutput

flush

public void flush()
Description copied from interface: IOutput
Flushes the logs

Specified by:
flush in interface IOutput

setFlush

public boolean setFlush(boolean v)
Description copied from interface: IOutput
Sets whether the Output flushes its announcements.

Specified by:
setFlush in interface IOutput

setVerbosity

public int setVerbosity(int v)
Description copied from interface: IOutput
Sets the Output object's general verbosity to v.

Specified by:
setVerbosity in interface IOutput

getVerbosity

public int getVerbosity()
Description copied from interface: IOutput
Returns the Output object's general verbosity

Specified by:
getVerbosity in interface IOutput

addLog

public int addLog(java.io.File filename,
                  int _verbosity,
                  boolean postAnnouncements,
                  boolean appendOnRestart,
                  boolean gzip)
           throws java.io.IOException
Description copied from interface: IOutput
Creates a new log of minimal verbosity verbosity and adds it to Output. This log will write to the file filename, and may or may not post announcements to the log. If the log must be reset upon restarting from a checkpoint, it will append to the file or erase the file and start over depending on appendOnRestart. If appendOnRestart is false and postAnnouncements is true, then this log will repost all the announcements on restarting from a checkpoint. Returns the position of the log in Output's collection of logs -- you should use this to access the log always; never store the log itself, which may go away upon a system restart. The log can be compressed with gzip, but you cannot appendOnRestart and compress at the same time.

Specified by:
addLog in interface IOutput
Throws:
java.io.IOException

addLog

public int addLog(java.io.File filename,
                  int _verbosity,
                  boolean postAnnouncements,
                  boolean appendOnRestart)
           throws java.io.IOException
Description copied from interface: IOutput
Creates a new log of minimal verbosity verbosity and adds it to Output. This log will write to the file filename, and may or may not post announcements to the log. If the log must be reset upon restarting from a checkpoint, it will append to the file or erase the file and start over depending on appendOnRestart. If appendOnRestart is false and postAnnouncements is true, then this log will repost all the announcements on restarting from a checkpoint. Returns the position of the log in Output's collection of logs -- you should use this to access the log always; never store the log itself, which may go away upon a system restart.

Specified by:
addLog in interface IOutput
Throws:
java.io.IOException

addLog

public int addLog(int descriptor,
                  int _verbosity,
                  boolean postAnnouncements)
Description copied from interface: IOutput
Creates a new log of minimal verbosity verbosity and adds it to Output. This log will write to stdout (descriptor == Log.D_STDOUT) or stderr (descriptor == Log.D_STDERR), and may or may not post announcements to the log. Returns the position of the log in Output's collection of logs -- you should use this to access the log always; never store the log itself, which may go away upon a system restart.

Specified by:
addLog in interface IOutput

addLog

public int addLog(java.io.Writer writer,
                  LogRestarter restarter,
                  int _verbosity,
                  boolean postAnnouncements,
                  boolean repostAnnouncements)

addLog

public int addLog(Log l)

numLogs

public int numLogs()

log

public Log log(int x)

removeLog

public Log removeLog(int x)

initialError

public static void initialError(java.lang.String s)
Prints an initial error to System.err. This is only to be used by ec.Evolve in starting up the system.


initialError

public static void initialError(java.lang.String s,
                                Parameter p1)
Prints an initial error to System.err. This is only to be used by ec.Evolve in starting up the system.


initialError

public static void initialError(java.lang.String s,
                                Parameter p1,
                                Parameter p2)
Prints an initial error to System.err. This is only to be used by ec.Evolve in starting up the system.


systemMessage

public void systemMessage(java.lang.String s)
Description copied from interface: IOutput
Posts a system message.

Specified by:
systemMessage in interface IOutput

fatal

public void fatal(java.lang.String s)
Description copied from interface: IOutput
Posts a fatal error. This causes the system to exit.

Specified by:
fatal in interface IOutput

fatal

public void fatal(java.lang.String s,
                  Parameter p1)
Description copied from interface: IOutput
Posts a fatal error. This causes the system to exit.

Specified by:
fatal in interface IOutput

fatal

public void fatal(java.lang.String s,
                  Parameter p1,
                  Parameter p2)
Description copied from interface: IOutput
Posts a fatal error. This causes the system to exit.

Specified by:
fatal in interface IOutput

error

public void error(java.lang.String s)
Description copied from interface: IOutput
Posts a simple error. This causes the error flag to be raised as well.

Specified by:
error in interface IOutput

error

public void error(java.lang.String s,
                  Parameter p1)
Description copied from interface: IOutput
Posts a simple error. This causes the error flag to be raised as well.

Specified by:
error in interface IOutput

error

public void error(java.lang.String s,
                  Parameter p1,
                  Parameter p2)
Description copied from interface: IOutput
Posts a simple error. This causes the error flag to be raised as well.

Specified by:
error in interface IOutput

warning

public void warning(java.lang.String s,
                    Parameter p1,
                    Parameter p2)
Description copied from interface: IOutput
Posts a warning.

Specified by:
warning in interface IOutput

warning

public void warning(java.lang.String s,
                    Parameter p1)
Description copied from interface: IOutput
Posts a warning.

Specified by:
warning in interface IOutput

warning

public void warning(java.lang.String s)
Description copied from interface: IOutput
Posts a warning.

Specified by:
warning in interface IOutput

warnOnce

public void warnOnce(java.lang.String s)
Description copied from interface: IOutput
Posts a warning one time only.

Specified by:
warnOnce in interface IOutput

warnOnce

public void warnOnce(java.lang.String s,
                     Parameter p1)
Specified by:
warnOnce in interface IOutput

warnOnce

public void warnOnce(java.lang.String s,
                     Parameter p1,
                     Parameter p2)
Specified by:
warnOnce in interface IOutput

message

public void message(java.lang.String s)
Description copied from interface: IOutput
Posts a message.

Specified by:
message in interface IOutput

reopen

public void reopen(int _log)
            throws java.io.IOException
Throws:
java.io.IOException

reopen

public void reopen(int[] _logs)
            throws java.io.IOException
Throws:
java.io.IOException

println

protected void println(java.lang.String s,
                       int _verbosity,
                       Log log,
                       boolean _announcement,
                       boolean _reposting)
                throws OutputException
Prints a message to a given log, with a certain verbosity. _announcement indicates that the message is an announcement.

Throws:
OutputException

println

public void println(java.lang.String s,
                    int _verbosity,
                    int log,
                    boolean _announcement)
             throws OutputException
Description copied from interface: IOutput
Prints a message to a given log, with a certain verbosity. If log==ALL_LOGS, posted to all logs.

Specified by:
println in interface IOutput
Throws:
OutputException

println

public void println(java.lang.String s,
                    int _verbosity,
                    int[] _logs)
             throws OutputException
Description copied from interface: IOutput
Prints a non-announcement message to the given logs, with a certain verbosity.

Specified by:
println in interface IOutput
Throws:
OutputException

println

public void println(java.lang.String s,
                    int _verbosity,
                    int log)
             throws OutputException
Description copied from interface: IOutput
Prints a non-announcement message to the given logs, with a certain verbosity.

Specified by:
println in interface IOutput
Throws:
OutputException

print

protected void print(java.lang.String s,
                     int _verbosity,
                     Log log)
              throws OutputException
Prints a non-announcement message to a given log, with a certain verbosity. No '\n' is printed.

Throws:
OutputException

print

public void print(java.lang.String s,
                  int _verbosity,
                  int log)
           throws OutputException
Description copied from interface: IOutput
Prints a non-announcement message to a given log, with a certain verbosity. If log==ALL_LOGS, posted to all logs. No '\n' is printed.

Specified by:
print in interface IOutput
Throws:
OutputException

print

public void print(java.lang.String s,
                  int _verbosity,
                  int[] _logs)
           throws OutputException
Description copied from interface: IOutput
Prints a non-announcement message to the given logs, with a certain verbosity. No '\n' is printed.

Specified by:
print in interface IOutput
Throws:
OutputException

exitIfErrors

public void exitIfErrors()
Description copied from interface: IOutput
Exits with a fatal error if the error flag has been raised.

Specified by:
exitIfErrors in interface IOutput

clearErrors

public void clearErrors()
Description copied from interface: IOutput
Clears the error flag.

Specified by:
clearErrors in interface IOutput

clearAnnouncements

public void clearAnnouncements()
Description copied from interface: IOutput
Clears out announcements. Note that this will cause these announcements to be unavailable for reposting after a restart!

Specified by:
clearAnnouncements in interface IOutput

restart

public void restart()
             throws java.io.IOException
Specified by:
restart in interface IOutput
Throws:
java.io.IOException