2021-04-29 15:10:34 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Text.RegularExpressions;
|
2022-03-23 10:41:59 -04:00
|
|
|
using EpicGames.Core;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2021-04-29 15:10:34 -04:00
|
|
|
|
2022-05-19 16:29:37 -04:00
|
|
|
#nullable enable
|
|
|
|
|
|
|
|
|
|
namespace AutomationUtils.Matchers
|
2021-04-29 15:10:34 -04:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Low-priority matcher for generic error strings like "warning:" and "error:"
|
|
|
|
|
/// </summary>
|
|
|
|
|
class GenericEventMatcher : ILogEventMatcher
|
|
|
|
|
{
|
2022-05-31 12:02:25 -04:00
|
|
|
static readonly Regex s_fatalPattern = new Regex(
|
|
|
|
|
@"^\s*(FATAL|fatal error):");
|
|
|
|
|
|
|
|
|
|
static readonly Regex s_warningErrorPattern = new Regex(
|
|
|
|
|
@"(?<!\w)(?i)(WARNING|ERROR) ?(\([^)]+\)|\[[^\]]+\])?: ");
|
|
|
|
|
|
|
|
|
|
static readonly Regex s_errorPattern = new Regex(
|
|
|
|
|
@"[Ee]rror [A-Z]\d+\s:");
|
|
|
|
|
|
2021-04-29 15:10:34 -04:00
|
|
|
/// <inheritdoc/>
|
2022-03-21 07:56:16 -04:00
|
|
|
public LogEventMatch? Match(ILogCursor cursor)
|
2021-04-29 15:10:34 -04:00
|
|
|
{
|
2022-03-21 07:56:16 -04:00
|
|
|
Match? match;
|
2022-05-31 12:02:25 -04:00
|
|
|
if (cursor.TryMatch(s_fatalPattern, out _))
|
2021-04-29 15:10:34 -04:00
|
|
|
{
|
2022-03-21 07:56:16 -04:00
|
|
|
return new LogEventBuilder(cursor).ToMatch(LogEventPriority.Low, LogLevel.Error, KnownLogEvents.Generic);
|
2021-04-29 15:10:34 -04:00
|
|
|
}
|
2022-05-31 12:02:25 -04:00
|
|
|
if (cursor.TryMatch(s_warningErrorPattern, out match))
|
2021-04-29 15:10:34 -04:00
|
|
|
{
|
2021-05-20 09:24:18 -04:00
|
|
|
// Careful to match the first WARNING or ERROR in the line here.
|
2022-03-21 07:56:16 -04:00
|
|
|
LogLevel level = LogLevel.Error;
|
|
|
|
|
if(match.Groups[1].Value.Equals("WARNING", StringComparison.OrdinalIgnoreCase))
|
2021-05-20 09:24:18 -04:00
|
|
|
{
|
2022-03-21 07:56:16 -04:00
|
|
|
level = LogLevel.Warning;
|
2021-05-20 09:24:18 -04:00
|
|
|
}
|
|
|
|
|
|
2022-06-08 16:37:49 -04:00
|
|
|
LogEventBuilder builder = new LogEventBuilder(cursor);
|
|
|
|
|
while (builder.IsNextLineHanging())
|
2021-04-29 15:10:34 -04:00
|
|
|
{
|
2022-03-21 07:56:16 -04:00
|
|
|
builder.MoveNext();
|
2021-04-29 15:10:34 -04:00
|
|
|
}
|
2022-03-21 07:56:16 -04:00
|
|
|
return builder.ToMatch(LogEventPriority.Lowest, level, KnownLogEvents.Generic);
|
2021-04-29 15:10:34 -04:00
|
|
|
}
|
2022-05-31 12:02:25 -04:00
|
|
|
if (cursor.IsMatch(s_errorPattern))
|
2021-04-29 15:10:34 -04:00
|
|
|
{
|
2022-03-21 07:56:16 -04:00
|
|
|
return new LogEventBuilder(cursor).ToMatch(LogEventPriority.Lowest, LogLevel.Error, KnownLogEvents.Generic);
|
2021-04-29 15:10:34 -04:00
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|