Files
UnrealEngineUWP/Engine/Source/Programs/AutomationTool/AutomationUtils/Matchers/LogChannelEventMatcher.cs
Ben Marsh 878f74458e Horde: Use long-lived regex instances for matching patterns.
#preflight 62963a2b95336ad2bfbfe846

[CL 20438090 by Ben Marsh in ue5-main branch]
2022-05-31 12:02:25 -04:00

54 lines
1.3 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System.Text.RegularExpressions;
using EpicGames.Core;
using Microsoft.Extensions.Logging;
#nullable enable
namespace AutomationUtils.Matchers
{
/// <summary>
/// Matches events formatted as UE log channel output
/// </summary>
class LogChannelEventMatcher : ILogEventMatcher
{
readonly static Regex s_pattern = new Regex(
@"^(\s*)" +
@"(?:\[[\d\.\-: ]+\])*" +
@"(?<channel>[a-zA-Z_][a-zA-Z0-9_]*):\s*" +
@"(?<severity>Error|Warning|Display): "
);
readonly static Regex s_indentPattern = new Regex(@"^\s+");
/// <inheritdoc/>
public LogEventMatch? Match(ILogCursor input)
{
Match? match = s_pattern.Match(input.CurrentLine!);
if (match.Success)
{
LogEventBuilder builder = new LogEventBuilder(input.Hanging());
builder.Annotate(match.Groups["channel"], LogEventMarkup.Channel);
builder.Annotate(match.Groups["severity"], LogEventMarkup.Severity);
while(builder.Next.CurrentLine != null)
{
builder.MoveNext();
}
LogLevel level = match.Groups["severity"].Value switch
{
"Error" => LogLevel.Error,
"Warning" => LogLevel.Warning,
_ => LogLevel.Information,
};
return builder.ToMatch(LogEventPriority.Low, level, KnownLogEvents.Engine_LogChannel);
}
return null;
}
}
}