Package mars.assembler.log
Class AssemblerLog
java.lang.Object
mars.assembler.log.AssemblerLog
A log for keeping track of errors occurring during the assembly process, whether during tokenizing, parsing,
or assembling. While simply throwing an
AssemblyError
would be a valid way to report errors, using this
log allows multiple LogMessage
s with varying LogLevel
s to be recorded in a single pass.
The original version of this class, written by Pete Sanderson, was called ErrorList
.
- Author:
- Pete Sanderson, August 2003; Sean Clarke, October 2024
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear all messages from the log.int
Get the maximum number of errors which can be produced by a single assembler run.int
Count the total number of logged messages, regardless of level.int
getMessageCount
(LogLevel level) Count the number of logged messages with a given level.Get the list of all logged messages, regardless of level, in chronological order.boolean
Determine whether the current number of errors logged exceeds the maximum error count, indicating that the assembler should exit as soon as possible.boolean
hasMessages
(LogLevel level) Determine whether at least one message has been logged with a given level.void
log
(LogLevel level, SourceLocation location, String content) void
log
(LogMessage message) Log a message for the current assembler run.void
logError
(SourceLocation location, String content) void
logInfo
(SourceLocation location, String content) void
logWarning
(SourceLocation location, String content) void
setMaxErrorCount
(int maxErrorCount) Set the maximum number of errors which can be produced by a single assembler run.void
setOutput
(Consumer<LogMessage> output)
-
Constructor Details
-
AssemblerLog
public AssemblerLog()Create a new, emptyAssemblerLog
.
-
-
Method Details
-
clear
public void clear()Clear all messages from the log. -
getMessages
Get the list of all logged messages, regardless of level, in chronological order.- Returns:
- The list of logged messages.
-
getMessageCount
public int getMessageCount()Count the total number of logged messages, regardless of level.- Returns:
- The number of messages.
-
getMessageCount
Count the number of logged messages with a given level.- Parameters:
level
- The level used to filter messages.- Returns:
- The number of messages whose level is
level
.
-
hasMessages
Determine whether at least one message has been logged with a given level. This method is equivalent to the expressiongetMessageCount(level) > 0
.- Parameters:
level
- The level used to filter messages.- Returns:
true
if at least one message has been logged with levellevel
, orfalse
if no such messages have been logged.
-
getMaxErrorCount
public int getMaxErrorCount()Get the maximum number of errors which can be produced by a single assembler run.- Returns:
- The maximum number of messages with level
LogLevel.ERROR
that can be logged.
-
setMaxErrorCount
public void setMaxErrorCount(int maxErrorCount) Set the maximum number of errors which can be produced by a single assembler run.- Parameters:
maxErrorCount
- The maximum number of messages with levelLogLevel.ERROR
that can be logged.
-
hasExceededMaxErrorCount
public boolean hasExceededMaxErrorCount()Determine whether the current number of errors logged exceeds the maximum error count, indicating that the assembler should exit as soon as possible.- Returns:
true
if the error count exceeds the maxiumm, orfalse
otherwise.- See Also:
-
setOutput
-
log
Log a message for the current assembler run. After this call, the newly logged message is considered to be the last message in chronological order.- Parameters:
message
- The message to log
-
log
-
logInfo
-
logWarning
-
logError
-