Repository navigation
Cleanup of IdeLogEntry, IdeLogListener and IdeGuiLogListener #2385
Description
Task summary
This ticket collects the review suggestions from #2053 (review) that were not resolved before merging. Things to do:
1. IdeLogListener takes an IdeLogEntry as its only argument
- Change
IdeLogListener.onLog(IdeLogLevel, String, String, Object[], Throwable)toboolean onLog(IdeLogEntry entry). Slf4jLoggerAdapter.handleNormalizedLoggingCallbuilds theIdeLogEntryonce and passes it to the listener.- Update all implementations:
IdeLogListenerBuffer(adds the entry directly instead of creating a new one),IdeLogListenerNone,IdeGuiLogListenerandIdeLogListenerCollector(test). - Creating an
IdeLogEntryfor every log event costs very little, and the simpler API is worth it.
2. IdeLogEntry: timestamp as Instant
- Change the record component
Long timeStamptoInstant timestampand create it withInstant.now(). AnInstantis readable in the debugger and intoString(), while alongis just a large number. - In
displayValue(), make theDateTimeFormatterastatic finalconstant instead of creating it on every call. Use theInstantdirectly. - Add the missing
@paramJavadoc for the timestamp.
3. IdeGuiLogListener: show each message only once
At the moment onLog ignores the return value of super.onLog(...) and always returns true. While the listener is buffering (the default after the constructor), a message:
- goes into the buffer and is still written to the GUI console at once,
- is passed on to the regular logger, even though buffering should suppress it,
- is written to the console a second time when the buffer is flushed.
Fix: only forward the message if the parent class accepts it:
boolean accept = super.onLog(entry);
if (accept && (this.consoleController != null)) {
this.consoleController.appendOutput(entry);
}
return accept;4. ConsoleController works with IdeLogEntry
IdeGuiLogListenerpasses the wholeIdeLogEntryto the controller. It no longer passes onlylevel+message, and it no longer adds a separate line" Error: " + error.getMessage()at the hard-codedERRORlevel.- The controller stores the full entry, including
error(), so the GUI can show the exception later. - Check whether the convenience methods
appendOutput(String)andappendOutput(IdeLogLevel, String)are still needed (they are used byGuiOutputListener,CommandletServiceandConsolePanelTest).
Out of scope (follow-up ticket): In the console, mark entries that have an exception with an icon. Clicking the icon opens a popup with the full stack trace, which can be scrolled and has a "copy to clipboard" button. This ticket only has to make sure the API keeps the Throwable available for that.
Acceptance criteria
-
IdeLogListener.onLog(IdeLogEntry)is the only listener method, and all implementations are migrated. -
IdeLogEntryusesInstantfor the timestamp, anddisplayValue()uses a constant formatter. - While buffering, a message logged in the GUI shows up exactly once in the console and is not passed on to the regular logger.
-
ConsoleControllerreceives and storesIdeLogEntryobjects, including the error. - Tests are adjusted or added, at least for the buffering case in
IdeGuiLogListener.
Additional context
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields🏗 In progress
Activity
[-]Cleanup of IdeLogEntry and IdeGuiListener[/-][+]Cleanup of IdeLogEntry, IdeLogListener and IdeGuiLogListener[/+]devonfw#2385 cleanup