mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-05-07 09:59:28 +00:00
* ci(docker): build dist-tests images * Update to .net 10, kubernetes client 18.0.13 Kubernetes client 18.0.13 is compatible with Kubernetes 1.34.x. The Kubernetes version is selected automatically by kubeadm in docker desktop (v1.34.1). See https://github.com/kubernetes-client/csharp#version-compatibility for a compatibility table. * Updates to support Kubernetes upgrade * bump openapi.yaml to match openapi.yaml in the logos-storage-nim docker image * bump doc to .net 10 * bump docker to .net 10 * Build image with latest tag always Always build an image with a latest tag (as well as a sha commit hash) when there's a push to master * docker image tag as "latest" only when pushing to master * Update docker image to install doctl * Remove doctl install kubeconfig is now created and uses a plain bearer token instead of using doctl as a credential mgr * Rename and remove all instances of Codex * Further remove CodexNetDeployer as it is no longer needed --------- Co-authored-by: Adam Uhlíř <adam@uhlir.dev>
106 lines
3.4 KiB
C#
106 lines
3.4 KiB
C#
using System.Globalization;
|
|
|
|
namespace LogosStorageClient
|
|
{
|
|
public class LogosStorageLogLine
|
|
{
|
|
public static LogosStorageLogLine? Parse(string line)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(line) ||
|
|
line.Length < 34 ||
|
|
line[3] != ' ' ||
|
|
line[33] != ' ') return null;
|
|
|
|
line = line.Replace(Environment.NewLine, string.Empty);
|
|
|
|
var level = line.Substring(0, 3);
|
|
var dtLine = line.Substring(4, 23);
|
|
|
|
var firstEqualSign = line.IndexOf('=');
|
|
var msgStart = 34;
|
|
var msgEnd = line.Substring(0, firstEqualSign).LastIndexOf(' ');
|
|
var msg = line.Substring(msgStart, msgEnd - msgStart).Trim();
|
|
var attrsLine = line.Substring(msgEnd);
|
|
|
|
var attrs = SplitAttrs(attrsLine);
|
|
|
|
var format = "yyyy-MM-dd HH:mm:ss.fff";
|
|
var dt = DateTime.ParseExact(dtLine, format, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime();
|
|
|
|
return new LogosStorageLogLine()
|
|
{
|
|
LogLevel = level,
|
|
TimestampUtc = dt,
|
|
Message = msg,
|
|
Attributes = attrs
|
|
};
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public string LogLevel { get; set; } = string.Empty;
|
|
public DateTime TimestampUtc { get; set; }
|
|
public string Message { get; set; } = string.Empty;
|
|
public Dictionary<string, string> Attributes { get; private set; } = new Dictionary<string, string>();
|
|
|
|
/// <summary>
|
|
/// After too much time spent cursing at regexes, here's what I got:
|
|
/// Parses input string into 'key=value' pair, considerate of quoted (") values.
|
|
/// </summary>
|
|
private static Dictionary<string, string> SplitAttrs(string input)
|
|
{
|
|
input += " ";
|
|
var result = new Dictionary<string, string>();
|
|
|
|
var key = string.Empty;
|
|
var value = string.Empty;
|
|
var mode = 1;
|
|
var inQuote = false;
|
|
|
|
foreach (var c in input)
|
|
{
|
|
if (mode == 1)
|
|
{
|
|
if (c == '=') mode = 2;
|
|
else if (c == ' ')
|
|
{
|
|
if (string.IsNullOrEmpty(key)) continue;
|
|
else
|
|
{
|
|
result.Add(key, string.Empty);
|
|
key = string.Empty;
|
|
value = string.Empty;
|
|
}
|
|
}
|
|
else key += c;
|
|
}
|
|
else if (mode == 2)
|
|
{
|
|
if (c == ' ' && !inQuote)
|
|
{
|
|
result.Add(key, value);
|
|
key = string.Empty;
|
|
value = string.Empty;
|
|
mode = 1;
|
|
}
|
|
else if (c == '\"')
|
|
{
|
|
inQuote = !inQuote;
|
|
}
|
|
else
|
|
{
|
|
value += c;
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|