Skip to content

Preserve bracket fields and message when SquareBracketColumnizer applies a time offset - #754

Merged
Hirogen merged 2 commits into
LogExperts:Developmentfrom
EnesKartal:fix/issue-713
Nov 22, 2026
Merged

Hirogen merged 2 commits into
LogExperts:Developmentfrom
EnesKartal:fix/issue-713

Conversation

@EnesKartal

Copy link
Copy Markdown
Contributor

Fixes #713

Root Cause

In SquareBracketColumnizer.SplitLine, when _timeOffset != 0, only the reformatted timestamp string (newDate) was passed to SquareSplit, discarding the remainder of the log line starting at endPos. As a result, all bracketed fields and the message column were returned empty.

Fix

  • Concatenate newDate with temp.Span[endPos..] before passing the shifted line to SquareSplit (using newDate.Length as the timestamp end position).
  • Leave the underlying ILogLineMemory.FullLine unmodified.

Tests

  • Added SplitLine_TimeOffset_PreservesBracketFieldsAndMessage covering zero, positive (+123 ms), negative (-506 ms), and reset-to-zero offsets.
  • Added SplitLine_TimeOffsetCrossesMidnight_ShiftsDateAndPreservesRemainingColumns covering forward and backward date rollovers.
  • Ran SquareBracketColumnizerTest and MarkerColumnizerSnapshotTests (12 passed, 0 failed) and the full LogExpert.Tests suite (1032 passed, 7 skipped, 0 failed).

@Hirogen Hirogen closed this Nov 20, 2026
@Hirogen Hirogen reopened this Nov 20, 2026

@Hirogen Hirogen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for picking this up! The fix looks right. Using newDate.Length for the timestamp end position is actually more robust than endPos, and the tests cover exactly what #713 asked for (zero, positive and negative offsets, midnight rollover both ways, reset to 0, and the log line itself left unchanged).

Two small requests before I merge:

  1. Nested-bracket case under an offset. Could you add one test that applies a nonzero offset to a line with a nested field, e.g. 2022-03-21 11:34:34.505[INFO][ProgramName/MethodName[41]]Message, and checks that [ProgramName/MethodName[41]] stays one column? That's the #460 behavior, and it's the one column shape the new tests don't cover yet.
  2. Issue reference comment. Please put a one-line // Issue #713: ... comment above the new tests, like the existing #460 test has.

Optional: the Select(c => c.FullValue.ToString()) assertion appears six times, so a small helper would tidy it up. Inline is fine too.

Thanks again!

@EnesKartal

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Addressed in d541416:

  • Added \SplitLine_TimeOffsetWithNestedBrackets_KeepsInnerBracketsInOneColumn\ covering \2022-03-21 11:34:34.505[INFO][ProgramName/MethodName[41]]Message\ with a nonzero offset.
  • Added // Issue Square Bracket timeshift drops bracket fields and message #713: ...\ comments above each of the new tests.
  • Extracted a small \GetColumnTexts\ helper for the column value assertions.

@Hirogen Hirogen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the fix, @EnesKartal! This is approvable as is.

The root cause and fix look right. Before, only the reformatted timestamp went to SquareSplit, so every bracket and message column came back empty. Joining the rest of the line back on fixes that, and passing newDate.Length keeps the split position right even when the reformatted date has a different length. The tests cover positive and negative offsets, midnight in both directions, reset to 0 and nested brackets.

Optional suggestions, none blocking:

  1. Nested-bracket test: #713 asks that the result match what offset 0 produces. You could also call SplitLine with offset 0 and assert that the columns other than the time match, instead of relying only on fixed expected values.
  2. Comments: the // Issue #713: ... lines mostly repeat the test names. // Issue #713 alone would do.
  3. Test setup: the new SquareBracketColumnizer() + GetPriority("square.log", [...]) pair is repeated in three tests. A small helper would tidy that up. You could also move GetColumnTexts next to the other helper near Setup/TearDown.

Not for this PR: with the German dd MMM yyyy formats, month names vary in length, so the date/time columns are misaligned under an offset. Also, a timestamp that fails to parse still returns three "n/a" columns whatever the column count. Both problems are older than this PR. I opened a separate issue for them. (#759)

@Hirogen
Hirogen merged commit e0bcc6d into LogExperts:Development Nov 22, 2026
2 checks passed
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.

Square Bracket timeshift drops bracket fields and message

2 participants