Class Output
- java.lang.Object
-
- ec.util.Output
-
- All Implemented Interfaces:
- java.io.Serializable
public class Output extends java.lang.Object implements java.io.SerializableOutputs 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 verbosity 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.
- FATAL ERRORs. These errors cause the system to exit(1) immediately.
- 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.
- WARNINGs. These errors do not cause the system to exit under any circumstances.
- MESSAGEs. Useful facts printed out for the benefit of the user.
- SYSTEM MESSAGEs. Useful system-level facts printed out for the benefit of the user.
Output will also store all announcements in memory by default so as to reproduce them if it's restarted from a checkpoint. You can change this behavior also by
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classOutput.OutputExitException
-
Field Summary
Fields Modifier and Type Field and Description static intALL_MESSAGE_LOGSstatic intNO_LOGSWhen passed to print functions, doesn't do any printingstatic intV_NO_ERRORSDon't print warnings, messages, or simple errorsstatic intV_NO_GENERALThe standard verbosity to use if you don't want common reporting (like statistics)static intV_NO_MESSAGESDon't print messagesstatic intV_NO_WARNINGSDon't print warnings or messagesstatic intV_TOTALLY_SILENTNo verbosity at all, not even system messages or fatal errorsstatic intV_VERBOSETotal verbosity
-
Constructor Summary
Constructors Constructor and Description Output(boolean storeAnnouncementsInMemory)Creates a new, verbose, empty Output object.Output(boolean storeAnnouncementsInMemory, int _verbosity)Deprecated.Verbosity no longer has an effect.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description intaddLog(java.io.File file, boolean appendOnRestart)Creates a new log and adds it to Output.intaddLog(java.io.File file, boolean appendOnRestart, boolean gzip)Creates a new log and adds it to Output.intaddLog(java.io.File file, boolean postAnnouncements, boolean appendOnRestart, boolean gzip)Creates a new log and adds it to Output.intaddLog(java.io.File file, int _verbosity, boolean postAnnouncements, boolean appendOnRestart)Deprecated.Verbosity no longer has an effectintaddLog(java.io.File file, int _verbosity, boolean postAnnouncements, boolean appendOnRestart, boolean gzip)Deprecated.Verbosity no longer has an effect.intaddLog(int descriptor, boolean postAnnouncements)Creates a new log and adds it to Output.intaddLog(int descriptor, int _verbosity, boolean postAnnouncements)Deprecated.Verbosity no longer has an effectintaddLog(Log l)Adds the given log to Output.intaddLog(java.io.Writer writer, LogRestarter restarter, boolean postAnnouncements, boolean repostAnnouncements)Creates a new log and adds it to Output.intaddLog(java.io.Writer writer, LogRestarter restarter, int _verbosity, boolean postAnnouncements, boolean repostAnnouncements)Deprecated.Verbosity no longer has an effectvoidclearAnnouncements()Clears out announcements.voidclearErrors()Clears the error flag.voidclose()Closes the logs -- ONLY call this if you are preparing to quitvoiderror(java.lang.String s)Posts a simple error.voiderror(java.lang.String s, Parameter p1)Posts a simple error.voiderror(java.lang.String s, Parameter p1, Parameter p2)Posts a simple error.voidexitIfErrors()Exits with a fatal error if the error flag has been raised.voidfatal(java.lang.String s)Posts a fatal error.voidfatal(java.lang.String s, Parameter p1)Posts a fatal error.voidfatal(java.lang.String s, Parameter p1, Parameter p2)Posts a fatal error.voidflush()Flushes the logsbooleangetFlush()LoggetLog(int x)Returns the given log.booleangetStore()booleangetThrowsErrors()intgetVerbosity()Deprecated.Verbosity no longer has an effect.static voidinitialError(java.lang.String s)Prints an initial error to System.err.static voidinitialError(java.lang.String s, Parameter p1)Prints an initial error to System.err.static voidinitialError(java.lang.String s, Parameter p1, Parameter p2)Prints an initial error to System.err.static voidinitialMessage(java.lang.String s)Prints an initial message to System.err.static voidinitialWarning(java.lang.String s)Prints an initial warning to System.err.static voidinitialWarning(java.lang.String s, Parameter p1)Prints an initial warning to System.err.static voidinitialWarning(java.lang.String s, Parameter p1, Parameter p2)Prints an initial warning to System.err.static java.io.InputStreammakeCompressingInputStream(java.io.InputStream in)Returns a compressing input stream using JZLib (http://www.jcraft.com/jzlib/).static java.io.OutputStreammakeCompressingOutputStream(java.io.OutputStream out)Returns a compressing output stream using JZLib (http://www.jcraft.com/jzlib/).voidmessage(java.lang.String s)Posts a message.intnumLogs()Returns the number of logs currently posted.voidprint(java.lang.String s, int log)Prints a non-announcement message to a given log.voidprint(java.lang.String s, int[] _logs)Prints a non-announcement message to the given logs, with a certain verbosity.voidprint(java.lang.String s, int _verbosity, int log)Prints a non-announcement message to a given log, with a certain verbosity.voidprint(java.lang.String s, int _verbosity, int[] _logs)Deprecated.Verbosity no longer has any effectvoidprintln(java.lang.String s, int log)Prints a non-announcement message to the given logs, with a verbosity of V_NO_GENERAL.voidprintln(java.lang.String s, int log, boolean _announcement)Prints a message to a given log.voidprintln(java.lang.String s, int _verbosity, int log)Deprecated.Verbosity no longer has an effectvoidprintln(java.lang.String s, int _verbosity, int[] _logs)Deprecated.Verbosity no longer has an effectLogremoveLog(int x)Removes the given log.voidreopen(int _log)Forces a file-based log to reopen, erasing its previous contents.voidreopen(int[] _logs)Forces one or more file-based logs to reopen, erasing their previous contents.voidrestart()voidsetFilePrefix(java.lang.String filePrefix)voidsetFlush(boolean v)Deprecated.We now always flushvoidsetStore(boolean v)Sets whether the Output stores its announcements.voidsetThrowsErrors(boolean val)voidsetVerbosity(int v)Deprecated.Verbosity no longer has an effect.voidsystemMessage(java.lang.String s)Posts a system message.voidwarning(java.lang.String s)Posts a warning.voidwarning(java.lang.String s, Parameter p1)Posts a warning.voidwarning(java.lang.String s, Parameter p1, Parameter p2)Posts a warning.voidwarnOnce(java.lang.String s)Posts a warning one time only.voidwarnOnce(java.lang.String s, Parameter p1)voidwarnOnce(java.lang.String s, Parameter p1, Parameter p2)
-
-
-
Field Detail
-
V_VERBOSE
public static final int V_VERBOSE
Total verbosity- See Also:
- Constant Field Values
-
V_NO_MESSAGES
public static final int V_NO_MESSAGES
Don't print messages- See Also:
- Constant Field Values
-
V_NO_WARNINGS
public static final int V_NO_WARNINGS
Don't print warnings or messages- See Also:
- Constant Field Values
-
V_NO_GENERAL
public static final int V_NO_GENERAL
The standard verbosity to use if you don't want common reporting (like statistics)- See Also:
- Constant Field Values
-
V_NO_ERRORS
public static final int V_NO_ERRORS
Don't print warnings, messages, or simple errors- See Also:
- Constant Field Values
-
V_TOTALLY_SILENT
public static final int V_TOTALLY_SILENT
No verbosity at all, not even system messages or fatal errors- See Also:
- Constant Field Values
-
ALL_MESSAGE_LOGS
public static final int ALL_MESSAGE_LOGS
- See Also:
- Constant Field Values
-
NO_LOGS
public static final int NO_LOGS
When passed to print functions, doesn't do any printing- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Output
public Output(boolean storeAnnouncementsInMemory, int _verbosity)Deprecated. Verbosity no longer has an effect.Creates a new, verbose, empty Output object.
-
Output
public Output(boolean storeAnnouncementsInMemory)
Creates a new, verbose, empty Output object.
-
-
Method Detail
-
setFilePrefix
public void setFilePrefix(java.lang.String filePrefix)
-
setThrowsErrors
public void setThrowsErrors(boolean val)
-
getThrowsErrors
public boolean getThrowsErrors()
-
close
public void close()
Closes the logs -- ONLY call this if you are preparing to quit
-
flush
public void flush()
Flushes the logs
-
setFlush
public void setFlush(boolean v)
Deprecated. We now always flushSets whether the Output flushes its announcements.
-
getFlush
public boolean getFlush()
-
setStore
public void setStore(boolean v)
Sets whether the Output stores its announcements.
-
getStore
public boolean getStore()
-
setVerbosity
public void setVerbosity(int v)
Deprecated. Verbosity no longer has an effect.Sets the Output object's general verbosity to v.
-
getVerbosity
public int getVerbosity()
Deprecated. Verbosity no longer has an effect.Returns the Output object's general verbosity
-
addLog
public int addLog(java.io.File file, int _verbosity, boolean postAnnouncements, boolean appendOnRestart, boolean gzip) throws java.io.IOExceptionDeprecated. Verbosity no longer has an effect.Creates a new log of minimal verbosity verbosity and adds it to Output. This log will write to the file file, 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.- Throws:
java.io.IOException
-
addLog
public int addLog(java.io.File file, int _verbosity, boolean postAnnouncements, boolean appendOnRestart) throws java.io.IOExceptionDeprecated. Verbosity no longer has an effectCreates a new log of minimal verbosity verbosity and adds it to Output. This log will write to the file file, 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.- Throws:
java.io.IOException
-
addLog
public int addLog(java.io.File file, boolean postAnnouncements, boolean appendOnRestart, boolean gzip) throws java.io.IOExceptionCreates a new log and adds it to Output. This log will write to the file file, 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.- Throws:
java.io.IOException
-
addLog
public int addLog(java.io.File file, boolean appendOnRestart, boolean gzip) throws java.io.IOExceptionCreates a new log and adds it to Output. This log will write to the file file, and you 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. 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.- Throws:
java.io.IOException
-
addLog
public int addLog(java.io.File file, boolean appendOnRestart) throws java.io.IOExceptionCreates a new log and adds it to Output. This log will write to the file file, and you 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. 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.- Throws:
java.io.IOException
-
addLog
public int addLog(int descriptor, int _verbosity, boolean postAnnouncements)Deprecated. Verbosity no longer has an effectCreates 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.
-
addLog
public int addLog(int descriptor, boolean postAnnouncements)Creates a new log 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.
-
addLog
public int addLog(java.io.Writer writer, LogRestarter restarter, int _verbosity, boolean postAnnouncements, boolean repostAnnouncements)Deprecated. Verbosity no longer has an effectCreates a new log of minimal verbosity verbosity and adds it to Output. This log may or may not post announcements to the log, and if it does, it additionally may or may not repost all of its announcements to the log upon a restart. The log writes to writer, which is reset upon system restart by restarter. 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.
-
addLog
public int addLog(java.io.Writer writer, LogRestarter restarter, boolean postAnnouncements, boolean repostAnnouncements)Creates a new log and adds it to Output. This log may or may not post announcements to the log, and if it does, it additionally may or may not repost all of its announcements to the log upon a restart. The log writes to writer, which is reset upon system restart by restarter. 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.
-
addLog
public int addLog(Log l)
Adds the given log to Output. In general you shouldn't use this method unless you really really need something custom. 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.
-
numLogs
public int numLogs()
Returns the number of logs currently posted.
-
getLog
public Log getLog(int x)
Returns the given log.
-
removeLog
public Log removeLog(int x)
Removes the given log.
-
initialWarning
public static void initialWarning(java.lang.String s)
Prints an initial warning to System.err. This is only to be used by ec.Evolve in starting up the system.
-
initialWarning
public static void initialWarning(java.lang.String s, Parameter p1)Prints an initial warning to System.err. This is only to be used by ec.Evolve in starting up the system.
-
initialWarning
public static void initialWarning(java.lang.String s, Parameter p1, Parameter p2)Prints an initial warning 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)
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.
-
initialMessage
public static void initialMessage(java.lang.String s)
Prints an initial message to System.err. This is only to be used by ec.Evolve in starting up the system. These messages are not logged.
-
systemMessage
public void systemMessage(java.lang.String s)
Posts a system message.
-
fatal
public void fatal(java.lang.String s)
Posts a fatal error. This causes the system to exit.
-
fatal
public void fatal(java.lang.String s, Parameter p1)Posts a fatal error. This causes the system to exit.
-
fatal
public void fatal(java.lang.String s, Parameter p1, Parameter p2)Posts a fatal error. This causes the system to exit.
-
error
public void error(java.lang.String s)
Posts a simple error. This causes the error flag to be raised as well.
-
error
public void error(java.lang.String s, Parameter p1)Posts a simple error. This causes the error flag to be raised as well.
-
error
public void error(java.lang.String s, Parameter p1, Parameter p2)Posts a simple error. This causes the error flag to be raised as well.
-
warning
public void warning(java.lang.String s, Parameter p1)Posts a warning.
-
warning
public void warning(java.lang.String s)
Posts a warning.
-
warnOnce
public void warnOnce(java.lang.String s)
Posts a warning one time only.
-
warnOnce
public void warnOnce(java.lang.String s, Parameter p1)
-
message
public void message(java.lang.String s)
Posts a message.
-
reopen
public void reopen(int _log) throws java.io.IOExceptionForces a file-based log to reopen, erasing its previous contents. non-file logs ignore this.- Throws:
java.io.IOException
-
reopen
public void reopen(int[] _logs) throws java.io.IOExceptionForces one or more file-based logs to reopen, erasing their previous contents. non-file logs ignore this.- Throws:
java.io.IOException
-
println
public void println(java.lang.String s, int log, boolean _announcement) throws OutputExceptionPrints a message to a given log. If log==ALL_MESSAGE_LOGS, posted to all logs which accept announcements. If the log is NO_LOGS, nothing is printed.- Throws:
OutputException
-
println
public void println(java.lang.String s, int _verbosity, int[] _logs) throws OutputExceptionDeprecated. Verbosity no longer has an effectPrints a non-announcement message to the given logs, with a certain verbosity. If a log is NO_LOGS, nothing is printed to that log.- Throws:
OutputException
-
println
public void println(java.lang.String s, int _verbosity, int log) throws OutputExceptionDeprecated. Verbosity no longer has an effectPrints a non-announcement message to the given logs, with a certain verbosity. If the log is NO_LOGS, nothing is printed.- Throws:
OutputException
-
println
public void println(java.lang.String s, int log) throws OutputExceptionPrints a non-announcement message to the given logs, with a verbosity of V_NO_GENERAL. If the log is NO_LOGS, nothing is printed.- Throws:
OutputException
-
print
public void print(java.lang.String s, int _verbosity, int log) throws OutputExceptionPrints a non-announcement message to a given log, with a certain verbosity. If log==ALL_MESSAGE_LOGS, posted to all logs which accept announcements. No '\n' is printed. If the log is NO_LOGS, nothing is printed.- Throws:
OutputException
-
print
public void print(java.lang.String s, int log) throws OutputExceptionPrints a non-announcement message to a given log. If log==ALL_MESSAGE_LOGS, posted to all logs which accept announcements. No '\n' is printed. If the log is NO_LOGS, nothing is printed.- Throws:
OutputException
-
print
public void print(java.lang.String s, int _verbosity, int[] _logs) throws OutputExceptionDeprecated. Verbosity no longer has any effectPrints a non-announcement message to the given logs, with a certain verbosity. No '\n' is printed. If a log is NO_LOGS, nothing is printed to that log.- Throws:
OutputException
-
print
public void print(java.lang.String s, int[] _logs) throws OutputExceptionPrints a non-announcement message to the given logs, with a certain verbosity. No '\n' is printed. If a log is NO_LOGS, nothing is printed to that log.- Throws:
OutputException
-
exitIfErrors
public void exitIfErrors()
Exits with a fatal error if the error flag has been raised.
-
clearErrors
public void clearErrors()
Clears the error flag.
-
clearAnnouncements
public void clearAnnouncements()
Clears out announcements. Note that this will cause these announcements to be unavailable for reposting after a restart!
-
restart
public void restart() throws java.io.IOException- Throws:
java.io.IOException
-
makeCompressingInputStream
public static java.io.InputStream makeCompressingInputStream(java.io.InputStream in)
Returns a compressing input stream using JZLib (http://www.jcraft.com/jzlib/). If JZLib is not available on your system, this method will return null.
-
makeCompressingOutputStream
public static java.io.OutputStream makeCompressingOutputStream(java.io.OutputStream out)
Returns a compressing output stream using JZLib (http://www.jcraft.com/jzlib/). If JZLib is not available on your system, this method will return null.
-
-
DMelt 3.0 © DataMelt by jWork.ORG