Class Log
- Author:
- David Cok
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThis is an interface to be implemented by any Object that wants to hear log messages; the Object must register itself by calling Log.addListener.static interfaceOutput whose content is not yet known, e.g.classThis class logs to the standard PrintStreams out and diag. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List<Log.IListener> The list of listeners to send log messages tointNumber of errors logged since last clear -
Constructor Summary
ConstructorsConstructorDescriptionLog(SMT.Configuration smtConfig) Constructs a Log based on the given configuration, adding a StandardListener -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(Log.IListener listener) Adds a listenervoidClears all listenersvoidDiscards held output, e.g.voidflush()Logs held output, in order, up to the first pending output that is not yet readygetDiag()Returns the current diagnostic stream.getOut()Returns the current regular-output stream.voidhold(Log.IPendingOutput output) Holds a place in the output for content not yet known: until it is printed (seeflush()), later logging calls are held behind it, so that output stays in order.voidSends the call to any listeners.booleanWhether output is held (seehold(IPendingOutput))static StringlocationIndication(IPos pos, String prompt, SMT.Configuration smtConfig) Creates a two-line, compiler-style caret diagnostic pointing at the given position; the returned value does not have a final line termination.voidPrints the argument to any listeners (adds a line terminator).voidReports the error to any listeners.Reports the error to any listeners, returning the input.voidPrints the argument on the regular output stream, with a line termination added, and notifies any listeners.voidPrints the argument on the regular output stream and to any listenersvoidlogOutNoln(String message) Prints the argument on the regular output stream with no newline appended, and notifies any listeners.booleanremoveListener(Log.IListener listener) Removes a listener (found by using object equality ==)voidsetChannels(PrintStream out, PrintStream diag) Points both output channels at the given streams -- the one point through which every change to these two channels happens.voidThediagsibling ofsetRegularOutputChannel(String).voidPoints the regular-output channel at "stdout", "stderr", or -- for any other value -- opens (in append mode) the file so named, per :regular-output-channel's SMT-LIB semantics.<T> TReturns the computation's result, logging what it logs at once rather than holding it (e.g.
-
Field Details
-
numErrors
public int numErrorsNumber of errors logged since last clear -
listeners
The list of listeners to send log messages to
-
-
Constructor Details
-
Log
Constructs a Log based on the given configuration, adding a StandardListener
-
-
Method Details
-
getOut
Returns the current regular-output stream. -
getDiag
Returns the current diagnostic stream. -
setChannels
Points both output channels at the given streams -- the one point through which every change to these two channels happens. Never opens a new stream: callers construct whatever they want a channel to point at (including smtConfig.stdout/stderr for the standard streams) and hand it in here, and this Log never closes a stream supplied this way -- ownership of it stays with the caller. (To point a channel at a named file, with this Log itself managing that file's lifecycle, usesetRegularOutputChannel(String)/setDiagnosticOutputChannel(String)instead -- SMT-LIB's :regular-output-channel/:diagnostic-output-channel commands should go through those, not this method, directly.)Does close a stream this Log previously opened for a file, if it's being replaced here and isn't also the other channel's current value (guards the case where both channels were pointed at the same file).
-
setRegularOutputChannel
Points the regular-output channel at "stdout", "stderr", or -- for any other value -- opens (in append mode) the file so named, per :regular-output-channel's SMT-LIB semantics. If the channel was previously pointed at a file this Log opened itself (and that file isn't also the current diagnostic channel), closes it first. Throws IOException if a named file can't be opened; the channel is left unchanged in that case -- the caller (AbstractSolver/Solver_test's set_option) is responsible for turning that into the appropriate SMT-LIB error response.- Throws:
IOException
-
setDiagnosticOutputChannel
Thediagsibling ofsetRegularOutputChannel(String).- Throws:
IOException
-
hold
Holds a place in the output for content not yet known: until it is printed (seeflush()), later logging calls are held behind it, so that output stays in order. -
flush
public void flush()Logs held output, in order, up to the first pending output that is not yet ready -
unheld
Returns the computation's result, logging what it logs at once rather than holding it (e.g. while a solver's response is parsed, which an adapter may do with the channels redirected) -
discardHeld
public void discardHeld()Discards held output, e.g. when a run is aborted at an error in a pending response -
isHolding
public boolean isHolding()Whether output is held (seehold(IPendingOutput)) -
logOut
Prints the argument on the regular output stream and to any listeners -
logOut
Prints the argument on the regular output stream, with a line termination added, and notifies any listeners. -
logOutNoln
Prints the argument on the regular output stream with no newline appended, and notifies any listeners. -
logError
Reports the error to any listeners, returning the input. -
logError
Reports the error to any listeners. -
logDiag
Prints the argument to any listeners (adds a line terminator). -
indent
Sends the call to any listeners. -
addListener
Adds a listener -
clearListeners
public void clearListeners()Clears all listeners -
removeListener
Removes a listener (found by using object equality ==)- Parameters:
listener- the listener to add- Returns:
- true if the argument was in the list
-
locationIndication
Creates a two-line, compiler-style caret diagnostic pointing at the given position; the returned value does not have a final line termination.In non-interactive mode, the first line is the source text line containing
pos(if the error is more than 150 characters into a long line, that line is instead shown starting 20 characters before the error, prefixed with"... "; if the visible portion would still run past 150 characters, it is cut off there and suffixed with"...\n"). The second line reproduces the leading whitespace/tabs up to the error's start column -- matched against the prompt's width instead, in interactive mode -- followed by one^per character spanningpos's start-to-end range.- Parameters:
pos- the position to indicateprompt- the prompt with which to begin each linesmtConfig- the current configuration- Returns:
- a canonical string representation of the location
-