Files
UnrealEngineUWP/Engine/Source/Programs/AutomationTool/AutomationUtils/Matchers/LocalizationEventMatcher.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

58 lines
1.6 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 by the localization commandlet
/// </summary>
class LocalizationEventMatcher : ILogEventMatcher
{
static readonly Regex s_pattern = new Regex(
@"^(\s*)" +
@"(?:\[[\d\.\-: ]+\])*" +
@"(?<channel>LogLocTextHelper|LogGatherTextFromSourceCommandlet):\s*" +
@"(?<severity>Error|Warning|Display):\s+" +
@"(?<file>([a-zA-Z]:)?[^:/\\]*[/\\][^:]+[^\)])" +
@"(?:\((?<line>\d+)\))?" +
@":");
static readonly 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);
builder.AnnotateSourceFile(match.Groups["file"], "Engine");
builder.Annotate(match.Groups["line"], LogEventMarkup.LineNumber);
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.High, level, KnownLogEvents.Engine_Localization);
}
return null;
}
}
}