Commit graph

1 commit

Author SHA1 Message Date
Vadim Peretokin
7618ad74f6
fix: log no longer duplicates a line when logging is restarted (#9490)
#### Brief overview of PR changes/additions

When logging to a file is stopped and then started again, the last line
of the previous logging session was written into the new log a second
time, duplicating it.

Mudlet defers each received line for logging so a trigger can still gag
it with `deleteLine()` before it reaches the file. Stopping a log
flushes that one pending line via `TBuffer::logRemainingOutput()`, but
the deferred-logging state was never reset afterwards. On the next
start, the first `log()` call replayed that leftover pending line into
the new session through its deferred-flush path.

The fix resets the deferred-logging state (`lastTextToLog`,
`lastLoggedFromLine`, `lastloggedToLine`) after flushing, using the same
"nothing pending" convention (`-1`/`-1` + empty text) already used
elsewhere in `TBuffer` (`deleteLines()`, `shrinkBuffer()`).

#### Motivation for adding to Mudlet

Restarting logging should never duplicate a line. The duplicate quietly
corrupted logs for anyone who toggled logging off and on within the same
session.

#### Other info (issues closed, discussion etc)

Adds a functional test `LogRestartDuplicateLineTest` with two cases:

- `test_restartDoesNotDuplicateLastLine` - stops logging with a pending
line, restarts, and asserts the line appears exactly once (verified
fail-first: it appeared twice before the fix).
- `test_gaggedLineStaysOutOfLog` - guards the pre-existing gagged-line
rescue behaviour so this change does not regress it.

The change is isolated to `logRemainingOutput()`, which only runs when
logging is turned off, so the normal in-session deferred-logging path is
unaffected.

Assisted-by: Claude:claude-opus-4-8
2026-07-27 20:41:32 +02:00