Repository navigation
Preserve bracket fields and message when SquareBracketColumnizer applies a time offset - #754
Conversation
…ies a time offset
Hirogen
left a comment
There was a problem hiding this comment.
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:
- 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. - 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!
|
Thanks for the review! Addressed in d541416:
|
Hirogen
left a comment
There was a problem hiding this comment.
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:
- 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.
- Comments: the // Issue #713: ... lines mostly repeat the test names. // Issue #713 alone would do.
- 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)
Fixes #713
Root Cause
In
SquareBracketColumnizer.SplitLine, when_timeOffset != 0, only the reformatted timestamp string (newDate) was passed toSquareSplit, discarding the remainder of the log line starting atendPos. As a result, all bracketed fields and the message column were returned empty.Fix
newDatewithtemp.Span[endPos..]before passing the shifted line toSquareSplit(usingnewDate.Lengthas the timestamp end position).ILogLineMemory.FullLineunmodified.Tests
SplitLine_TimeOffset_PreservesBracketFieldsAndMessagecovering zero, positive (+123 ms), negative (-506 ms), and reset-to-zero offsets.SplitLine_TimeOffsetCrossesMidnight_ShiftsDateAndPreservesRemainingColumnscovering forward and backward date rollovers.SquareBracketColumnizerTestandMarkerColumnizerSnapshotTests(12 passed, 0 failed) and the fullLogExpert.Testssuite (1032 passed, 7 skipped, 0 failed).