forked from TensorStack-AI/TensorStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogParser.cs
More file actions
55 lines (47 loc) · 1.61 KB
/
LogParser.cs
File metadata and controls
55 lines (47 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Globalization;
namespace TensorStack.Python
{
internal record LogEntry(DateTime Timestamp, string Message);
internal static class LogParser
{
/// <summary>
/// Parses the python logs.
/// </summary>
/// <param name="logEntries">The log entries.</param>
/// <returns>IEnumerable<PipelineProgress>.</returns>
internal static IEnumerable<LogEntry> ParseLogs(IReadOnlyList<string> logEntries)
{
foreach (var logEntry in logEntries)
{
var progress = ParsePythonLog(logEntry);
if (progress == null)
continue;
yield return progress;
}
}
/// <summary>
/// Parses the python log.
/// </summary>
/// <param name="logEntry">The log entry.</param>
/// <returns>PythonProgress.</returns>
private static LogEntry ParsePythonLog(string logEntry)
{
try
{
var messageSections = logEntry.Split('|', 3, StringSplitOptions.TrimEntries).AsSpan();
if (messageSections.Length < 2)
return default;
var message = messageSections[1].Trim([' ', '\n', '\r']);
if (message.Length < 5)
return default;
return new LogEntry(DateTime.Parse(messageSections[0], CultureInfo.InvariantCulture), message);
}
catch (Exception)
{
return default;
}
}
}
}