Skip to content

Commit 4cfadff

Browse files
committed
fixup! Minimal changes to fix multiline logs
1 parent d59cd27 commit 4cfadff

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

Dalamud/Interface/Internal/Windows/ConsoleWindow.cs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public override void Draw()
208208
0); // Prevents flicker effect. Also workaround to avoid negative indexes.
209209
var line = this.filteredLogEntries[index];
210210

211-
if (!line.IsMultiline)
211+
if (line.IsFirstLine)
212212
ImGui.Separator();
213213

214214
if (line.SelectedForCopy)
@@ -236,7 +236,7 @@ public override void Draw()
236236

237237
ImGui.PopStyleColor(3);
238238

239-
if (!line.IsMultiline)
239+
if (line.IsFirstLine)
240240
{
241241
ImGui.Text(line.TimestampString);
242242
ImGui.SameLine();
@@ -942,7 +942,7 @@ private int HandleLogEvent(string line, LogEvent logEvent)
942942
List<LogLine> lines = [];
943943

944944
// create a LogEntry with this collection
945-
var logEntry = new LogEntry { Lines = lines };
945+
var logEntry = new LogEntry();
946946

947947
// try to get the source of the line, null otherwise
948948
string? source = null;
@@ -956,6 +956,8 @@ private int HandleLogEvent(string line, LogEvent logEvent)
956956
source = sourceValue;
957957
}
958958

959+
var first = true;
960+
959961
var ssp = line.AsSpan();
960962
while (true)
961963
{
@@ -967,8 +969,11 @@ private int HandleLogEvent(string line, LogEvent logEvent)
967969
TimeStamp = logEvent.Timestamp,
968970
HasException = logEvent.Exception != null,
969971
Source = source,
972+
IsFirstLine = first,
970973
};
971974

975+
first = false;
976+
972977
var nextLineSeparator = ssp.IndexOfAny('\r', '\n');
973978
if (nextLineSeparator == -1)
974979
{
@@ -984,9 +989,6 @@ private int HandleLogEvent(string line, LogEvent logEvent)
984989
// push the line into the lines list
985990
lines.Add(logLine);
986991

987-
// Mark further lines as multiline.
988-
logLine.IsMultiline = true;
989-
990992
// Skip the detected line break.
991993
ssp = ssp[nextLineSeparator..];
992994
ssp = ssp.StartsWith("\r\n") ? ssp[2..] : ssp[1..];
@@ -1154,31 +1156,37 @@ private unsafe void DrawHighlighted(
11541156
}
11551157

11561158

1157-
private record LogEntry
1159+
/// <summary>
1160+
/// This class is only used to differentiate the entry a log line belongs to.
1161+
/// Cannot be a record, because a record would have value equality instead of referential equality.
1162+
/// </summary>
1163+
private class LogEntry
11581164
{
1159-
public IEnumerable<LogLine> Lines { get; init; }
11601165
}
11611166

11621167
private record LogLine
11631168
{
11641169
public string Line { get; set; } = string.Empty;
11651170

11661171
/// <summary>
1167-
/// The corresponding log entry for the line, used to group lines when filtering
1172+
/// Gets or sets the corresponding log entry for the line, used to group lines when filtering.
11681173
/// </summary>
11691174
public LogEntry Entry { get; init; }
11701175

11711176
public LogEventLevel Level { get; init; }
11721177

11731178
public DateTimeOffset TimeStamp { get; init; }
11741179

1175-
public bool IsMultiline { get; set; }
1180+
/// <summary>
1181+
/// Gets or sets a value indicating whether this line is the first line in its LogEntry. If true, it may or may not be the only line.
1182+
/// </summary>
1183+
public bool IsFirstLine { get; set; }
11761184

11771185
/// <summary>
11781186
/// Gets or sets the system responsible for generating this log entry. Generally will be a plugin's
11791187
/// InternalName.
11801188
/// </summary>
1181-
public string? Source { get; set; }
1189+
public string? Source { get; init; }
11821190

11831191
public bool SelectedForCopy { get; set; }
11841192

@@ -1189,9 +1197,9 @@ private record LogLine
11891197
public string TimestampString => this.TimeStamp.ToString("HH:mm:ss.fff");
11901198

11911199
public override string ToString() =>
1192-
this.IsMultiline
1193-
? $"\t{this.Line}"
1194-
: $"{this.TimestampString} | {GetTextForLogEventLevel(this.Level)} | {this.Line}";
1200+
this.IsFirstLine
1201+
? $"{this.TimestampString} | {GetTextForLogEventLevel(this.Level)} | {this.Line}"
1202+
: $"\t{this.Line}";
11951203
}
11961204

11971205
private class PluginFilterEntry

0 commit comments

Comments
 (0)