Class DefaultFixtureLogger
- All Implemented Interfaces:
FixtureLogger,AggregatingFixtureLogger
FixtureLogger usually used in Integrity.- Author:
- Rene Schneider - initial API and implementation
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ConsoleOutputInterceptorThe console interceptor.protected static final charThe escape character, which can be used to actually put thePARAM_STRpattern into a log message without it being replaced.protected static final StringThe prefix for fixture log lines that are being printed on the console.static final StringSet this system property to turn on verbose logging of fixture log output.All logged lines are collected here.protected static final charParameter placeholders are started with this char.protected static final charParameter placeholders end with this char.protected static final StringThis string is the parameter placeholder.The unmodifiable collection returned to callers is cached here, in case multiple callers need the same one.protected FixtureLogLevelOnly log messages that equal this level or are coarser than it will be logged. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendParameter(StringBuilder aBuffer, Object aParam) Appends the given parameter (which can be an array or a single object).protected voidappendSimpleObjectParameter(StringBuilder aBuffer, Object aParam) Appends the given parameter, which at this point must be a single object.voidClears any lines currently stored in the logger.voidLog the specified message atFixtureLogLevel.DEBUGlevel.voidLog the specified message atFixtureLogLevel.ERRORlevel.getLines()Returns the currently aggregated log lines, but does NOT clear the buffer.voidLog the specified message atFixtureLogLevel.INFOlevel.voidlog(FixtureLogLevel aLevel, String aMessage, Object... someParameters) Log the specified message at the specified log level.protected voidprintLogLine(LogLine aLine) Prints the log line on the console.protected StringreplaceParameterPlaceholders(String aMessage, Object... someParameters) Replaces all parameter placeholders in the given message with the given parameters.voidsetThresholdLevel(FixtureLogLevel aThresholdLevel) Sets the threshold level interactively at runtime.stackTraceToLogLines(Throwable anException, FixtureLogLevel aLevel) Formats a stack trace into a list of log lines.voidLog the specified message atFixtureLogLevel.TRACElevel.voidLog the specified message atFixtureLogLevel.WARNINGlevel.
-
Field Details
-
loggedLines
All logged lines are collected here. -
resultLoggedLines
The unmodifiable collection returned to callers is cached here, in case multiple callers need the same one. -
thresholdLevel
Only log messages that equal this level or are coarser than it will be logged. -
LOG_TRACE_PROPERTY
Set this system property to turn on verbose logging of fixture log output. Log output on levelFixtureLogLevel.TRACEwill not be actually logged otherwise, since the default level isFixtureLogLevel.DEBUG.- See Also:
-
consoleOutputInterceptor
The console interceptor. -
FIXTURE_LOG_CONSOLE_PREFIX
The prefix for fixture log lines that are being printed on the console.- See Also:
-
PARAM_START
protected static final char PARAM_STARTParameter placeholders are started with this char.- See Also:
-
PARAM_STOP
protected static final char PARAM_STOPParameter placeholders end with this char.- See Also:
-
PARAM_STR
This string is the parameter placeholder.- See Also:
-
ESCAPE_CHAR
protected static final char ESCAPE_CHARThe escape character, which can be used to actually put thePARAM_STRpattern into a log message without it being replaced. It can itself be escaped by prepending it with itself.- See Also:
-
-
Constructor Details
-
DefaultFixtureLogger
public DefaultFixtureLogger()
-
-
Method Details
-
setThresholdLevel
Sets the threshold level interactively at runtime. Only log messages that equal this level or are coarser than it will be logged.- Parameters:
aThresholdLevel- the level to compare with
-
getLines
Description copied from interface:AggregatingFixtureLoggerReturns the currently aggregated log lines, but does NOT clear the buffer. This method guarantees to return a finalized collection that will not be modified anymore by the aggregator.- Specified by:
getLinesin interfaceAggregatingFixtureLogger- Returns:
- the logged lines
-
clearLines
public void clearLines()Description copied from interface:AggregatingFixtureLoggerClears any lines currently stored in the logger.- Specified by:
clearLinesin interfaceAggregatingFixtureLogger
-
log
Description copied from interface:FixtureLoggerLog the specified message at the specified log level. The message may contain placeholders "{}" which will be replaced by the respective parameter provided (order of parameters is mapped onto order of placeholders). Non-String parameters are converted toStrings by calling toString().An exception is the last parameter: if it is a
Throwable, it is not considered to be a "normal" parameter for a placeholder. Instead, the stacktrace of theThrowableis logged as part of the log message.- Specified by:
login interfaceFixtureLogger- Parameters:
aLevel- the log levelaMessage- the message to log (possibly with placeholders)someParameters- parameters to insert into placeholders, optionally aThrowableat the end of the list
-
printLogLine
Prints the log line on the console.- Parameters:
aLine-
-
stackTraceToLogLines
Formats a stack trace into a list of log lines. This is more convenient for fixture logging purposes, even though it breaks with some common conventions regarding stack trace logging.- Parameters:
anException- the exception from which to get the stack trace- Returns:
- the stack trace as a list of
LogLines
-
error
Description copied from interface:FixtureLoggerLog the specified message atFixtureLogLevel.ERRORlevel. The message may contain placeholders "{}" which will be replaced by the respective parameter provided (order of parameters is mapped onto order of placeholders). Non-String parameters are converted toStrings by calling toString().An exception is the last parameter: if it is a
Throwable, it is not considered to be a "normal" parameter for a placeholder. Instead, the stacktrace of theThrowableis logged as part of the log message.- Specified by:
errorin interfaceFixtureLogger- Parameters:
aMessage- the message to log (possibly with placeholders)someParameters- parameters to insert into placeholders, optionally aThrowableat the end of the list
-
warn
Description copied from interface:FixtureLoggerLog the specified message atFixtureLogLevel.WARNINGlevel. The message may contain placeholders "{}" which will be replaced by the respective parameter provided (order of parameters is mapped onto order of placeholders). Non-String parameters are converted toStrings by calling toString().An exception is the last parameter: if it is a
Throwable, it is not considered to be a "normal" parameter for a placeholder. Instead, the stacktrace of theThrowableis logged as part of the log message.- Specified by:
warnin interfaceFixtureLogger- Parameters:
aMessage- the message to log (possibly with placeholders)someParameters- parameters to insert into placeholders, optionally aThrowableat the end of the list
-
info
Description copied from interface:FixtureLoggerLog the specified message atFixtureLogLevel.INFOlevel. The message may contain placeholders "{}" which will be replaced by the respective parameter provided (order of parameters is mapped onto order of placeholders). Non-String parameters are converted toStrings by calling toString().An exception is the last parameter: if it is a
Throwable, it is not considered to be a "normal" parameter for a placeholder. Instead, the stacktrace of theThrowableis logged as part of the log message.- Specified by:
infoin interfaceFixtureLogger- Parameters:
aMessage- the message to log (possibly with placeholders)someParameters- parameters to insert into placeholders, optionally aThrowableat the end of the list
-
debug
Description copied from interface:FixtureLoggerLog the specified message atFixtureLogLevel.DEBUGlevel. The message may contain placeholders "{}" which will be replaced by the respective parameter provided (order of parameters is mapped onto order of placeholders). Non-String parameters are converted toStrings by calling toString().An exception is the last parameter: if it is a
Throwable, it is not considered to be a "normal" parameter for a placeholder. Instead, the stacktrace of theThrowableis logged as part of the log message.- Specified by:
debugin interfaceFixtureLogger- Parameters:
aMessage- the message to log (possibly with placeholders)someParameters- parameters to insert into placeholders, optionally aThrowableat the end of the list
-
trace
Description copied from interface:FixtureLoggerLog the specified message atFixtureLogLevel.TRACElevel. The message may contain placeholders "{}" which will be replaced by the respective parameter provided (order of parameters is mapped onto order of placeholders). Non-String parameters are converted toStrings by calling toString().An exception is the last parameter: if it is a
Throwable, it is not considered to be a "normal" parameter for a placeholder. Instead, the stacktrace of theThrowableis logged as part of the log message.- Specified by:
tracein interfaceFixtureLogger- Parameters:
aMessage- the message to log (possibly with placeholders)someParameters- parameters to insert into placeholders, optionally aThrowableat the end of the list
-
replaceParameterPlaceholders
Replaces all parameter placeholders in the given message with the given parameters.- Parameters:
aMessage- the message to processsomeParameters- the parameters to insert- Returns:
- the finished message
-
appendParameter
Appends the given parameter (which can be an array or a single object).- Parameters:
aBuffer- the buffer to append toaParam- the parameter
-
appendSimpleObjectParameter
Appends the given parameter, which at this point must be a single object.- Parameters:
aBuffer- the buffer to append toaParam- the parameter
-