Skip to content

feat(ui): add a Clear Log button to the log view - #725

Merged
Cervator merged 3 commits into
masterfrom
feat/clear-log-button
Aug 15, 2026
Merged

feat(ui): add a Clear Log button to the log view#725
Cervator merged 3 commits into
masterfrom
feat/clear-log-button

Conversation

@soloturn

@soloturn soloturn commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #661.

Summary

The launcher's log view accumulates both its own output and everything the running game prints for as long as the launcher process stays alive. With the default "close launcher after game start" setting that's rarely an issue - but a failed launch keeps the launcher open instead of closing it, and retrying (adjust settings, launch again) piles each attempt's output onto the last one in the same view. Same story for anyone who's turned that setting off specifically to keep watching logs across multiple play sessions.

Adds a small "Clear Log" button above the log TextArea. Clears the buffered-but-not-yet-flushed text before the visible area, so a periodic flush racing in right after the click can't silently re-append stale content and undo the clear.

Test plan

  • Full ./gradlew build passes (compile, checkstyle, PMD, tests).
  • Manually launched the app (with "close after start" unchecked to accumulate real content across multiple game runs) and confirmed the button clears an already-populated log correctly.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d53e6fd3-ad53-43ba-b152-4200e36b34ab

📥 Commits

Reviewing files that changed from the base of the PR and between 5c35a8b and 8ec90fe.

📒 Files selected for processing (3)
  • src/main/java/org/terasology/launcher/ui/LogViewController.java
  • src/main/resources/org/terasology/launcher/bundle/LabelsBundle.properties
  • src/main/resources/org/terasology/launcher/bundle/LabelsBundle_en.properties
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/terasology/launcher/ui/LogViewController.java

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added a Clear Log button to the log view.
    • Clearing removes both displayed log messages and buffered entries.
    • Adjusted the log layout to accommodate the new control.
    • Added localized text for the clear action.
  • Bug Fixes

    • Prevented previously queued log updates from reappearing after the log is cleared.
    • Improved log update handling to keep displayed messages synchronized with the latest state.

Walkthrough

The log view now includes a Clear Log button. The controller clears buffered entries and displayed text. Scheduled flushes use the JavaFX application thread and ignore stale snapshots after clearing. The text area moves down for the button.

Changes

Log clearing

Layer / File(s) Summary
Generation-safe log flushing
src/main/java/org/terasology/launcher/ui/LogViewController.java
Scheduled flushes capture a generation, drain the buffer, and append on the JavaFX application thread only when the generation remains current.
Clear log flow
src/main/java/org/terasology/launcher/ui/LogViewController.java, src/main/resources/org/terasology/launcher/views/log-view.fxml, src/main/resources/org/terasology/launcher/bundle/LabelsBundle.properties, src/main/resources/org/terasology/launcher/bundle/LabelsBundle_en.properties
The clear action invalidates pending flushes, clears buffered entries, and clears displayed text. The FXML adds the localized Clear Log button and adjusts the text-area layout.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 8ec90

The PR adds a localized Clear Log control for accumulated launcher output and reports successful build and manual validation; no actionable merge-blocking risk remains.

Poem

I’m a rabbit with logs in my tray,
A button clears old lines away.
Stale flushes stop,
New entries can hop,
While JavaFX keeps them in play.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a Clear Log button to the log view.
Description check ✅ Passed The description explains the log accumulation problem and the implemented Clear Log behavior.
Linked Issues check ✅ Passed The changes implement issue #661 by adding a Clear Log button that removes visible and buffered log content.
Out of Scope Changes check ✅ Passed All changes support the Clear Log feature and prevent stale log content from reappearing after clearing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/clear-log-button

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/java/org/terasology/launcher/ui/LogViewController.java`:
- Around line 63-72: Update clearLogAction() and the scheduled flush
coordination to use a generation/token: increment it when clearing, capture it
with each buffer snapshot, and discard snapshots whose token is stale before
appending. Ensure all logArea.clear()/appendText() UI updates are dispatched
through Platform.runLater() on the JavaFX Application Thread.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 90a77567-85f9-48f2-a060-3ff767dba618

📥 Commits

Reviewing files that changed from the base of the PR and between da05b73 and c0e6f41.

📒 Files selected for processing (2)
  • src/main/java/org/terasology/launcher/ui/LogViewController.java
  • src/main/resources/org/terasology/launcher/views/log-view.fxml

Comment thread src/main/java/org/terasology/launcher/ui/LogViewController.java

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/java/org/terasology/launcher/ui/LogViewController.java`:
- Around line 52-66: Update the buffer-draining task around generation and
buffer so it reads and increments generation while holding the buffer monitor,
making the generation snapshot atomic with buffer.toString() and
buffer.setLength(0). Apply the same change to the corresponding logic noted
around the second occurrence, while preserving the existing FX-thread append
guard.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9e645ed7-db2b-4ea1-ad3c-6be8f1c77a55

📥 Commits

Reviewing files that changed from the base of the PR and between c0e6f41 and 5c35a8b.

📒 Files selected for processing (1)
  • src/main/java/org/terasology/launcher/ui/LogViewController.java

Comment thread src/main/java/org/terasology/launcher/ui/LogViewController.java Outdated
soloturn and others added 3 commits August 15, 2026 11:01
Fixes #661. The launcher's log view accumulates both its own output and
everything the running game prints for as long as the launcher process
stays alive. With the default 'close launcher after game start' setting
that's rarely an issue - but a failed launch keeps the launcher open
instead of closing it, and retrying (adjust settings, launch again)
piles each attempt's output onto the last one in the same view. Same
story for anyone who's turned that setting off specifically to keep
watching logs across multiple play sessions.

Clears the buffered-but-not-yet-flushed text before the visible
TextArea, so a flush racing in right after the click can't silently
re-append stale content and undo the clear.

Verified: full ./gradlew build passes; manually launched the app (with
'close after start' unchecked to accumulate real content across
multiple runs) and confirmed the button actually clears an
already-populated log.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V3dYofgD6GW7V21k6Mzfud
CodeRabbit review: my earlier fix (clear the buffer before logArea)
assumed the flush task's snapshot-then-append was atomic - it isn't.
The flush task releases the buffer lock right after taking its
snapshot, then appends separately; a clear landing in that window
still gets silently undone when the stale append finally runs.

Also fixes a real pre-existing bug the review surfaced along the way:
the flush task's appendText() call ran on its own background thread,
never wrapped in Platform.runLater() - a Task's call() does not run on
the JavaFX Application Thread, and JavaFX controls may only be mutated
from that thread. Wrapped it.

A generation counter, bumped by clearLogAction() and captured
alongside each flush's buffer snapshot, lets the (now Platform.runLater'd)
append discard itself if a clear happened since the snapshot was taken.
The increment and the discard check both happen on the FX Application
Thread, so there's no race between those two specifically.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V3dYofgD6GW7V21k6Mzfud
… race

The button's label was set in FXML, bypassing the mechanism every other control here uses: a placeholder in FXML plus `textProperty().bind(I18N.labelBinding(key))` in the controller. It would have read "Clear Log" in all seventeen supported languages, and — because `labelBinding` tracks `localeProperty` — it would have been the one control that didn't re-translate when the language is changed in Settings, sitting directly beneath tabs that do. Adds `tab_log_clear` to the key manifest and its English text, and binds it; other locales are left to translation as usual. The existing `fx:id` becomes load-bearing rather than decorative.

The generation counter was read outside the buffer lock, which left the window it exists to close still open, just narrower and inverted: a clear landing between the read and the drain tags text drained *after* the clear with the pre-clear generation, so the append discards log lines that belong on screen. Reading it and bumping it under the lock makes "which generation does this text belong to" an invariant rather than a matter of timing.

No change to the `Platform.runLater` wrapping, which is worth keeping on its own merits — `appendText` was being called off the FX Application Thread every two seconds before this branch.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Cervator
Cervator force-pushed the feat/clear-log-button branch from 5c35a8b to 8ec90fe Compare August 15, 2026 19:09
@agent-refr

Copy link
Copy Markdown

Rebased onto master (it had drifted behind after #727) and added a small follow-up commit with two things.

Localization. The button sets its label in FXML, which bypasses the mechanism the rest of the launcher uses — a placeholder in FXML plus textProperty().bind(I18N.labelBinding(key)) in the controller, which is why settings.fxml is full of giveaways like text="Button". As written it would read "Clear Log" in all seventeen supported languages, and since labelBinding tracks localeProperty, it would have been the one control that didn't re-translate when the language is changed in Settings — sitting directly under tabs that do. Added tab_log_clear to the key manifest plus its English text and bound it in initialize(); other locales are left to translation as usual. Side benefit: the fx:id is now actually injected rather than decorative.

The generation counter. Right instinct, but the read sat outside the buffer lock, which left the window it exists to close still open — just narrower, and inverted. If a clear lands between generation.get() and the synchronized drain, the flush tags text drained after the clear with the pre-clear generation, and the runLater check then discards log lines that belong on screen. Moved the read and the bump under the lock so the tag and the text it describes always agree.

One thing worth adding to the PR description rather than the code: wrapping appendText in Platform.runLater fixes a real pre-existing bug independent of the Clear button — on master it's called straight from Task.call(), i.e. off the FX Application Thread, every two seconds since launcher start. Right now that's invisible to a reader, who would assume the runLater exists only for the clear race and might simplify it away later. Worth a line so it doesn't get lost.

Verified compileJava and checkstyleMain pass (the three checkstyle warnings are pre-existing, in SettingsController and GithubRepository), and ran the launcher from source: the button renders and clearing behaves, with no missing-label warnings.

@Cervator
Cervator merged commit 48d70eb into master Aug 15, 2026
4 checks passed
@Cervator
Cervator deleted the feat/clear-log-button branch August 15, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add "Clear Log" button

3 participants