Skip to content

Commit 14bcaed

Browse files
committed
restore handling of the original level value
1 parent 5973667 commit 14bcaed

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/SeqCli/Ingestion/JsonLogEventReader.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ public static LogEvent ReadFromJObject(JObject jObject)
6868
if (!jObject.TryGetValue("@t", out _))
6969
jObject.Add("@t", new JValue(DateTime.UtcNow.ToString("O")));
7070

71+
if (jObject.TryGetValue("@l", out var levelToken))
72+
{
73+
var originalLevel = levelToken.Value<string>()!;
74+
jObject.Remove("@l");
75+
76+
var serilogLevel = LevelMapping.ToSerilogLevel(originalLevel);
77+
if (serilogLevel != LogEventLevel.Information)
78+
jObject.Add("@l", new JValue(serilogLevel.ToString()));
79+
80+
jObject.Add("SeqCliOriginalLevel", originalLevel);
81+
}
82+
7183
return LogEventReader.ReadFromJObject(jObject);
7284
}
7385
}

src/SeqCli/Output/OutputFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ namespace SeqCli.Output;
66
static class OutputFormatter
77
{
88
internal static readonly ITextFormatter Json = new ExpressionTemplate(
9-
"{ {@t, @mt, @l: if @l = 'Information' then undefined() else @l, @x, @sp, @tr, @ps, @st, ..rest()} }\n"
9+
"{ {@t, @mt, @l: coalesce(SeqCliOriginalLevel, if @l = 'Information' then undefined() else @l), @x, @sp, @tr, @ps, @st, ..rest()} }\n"
1010
);
1111
}

src/SeqCli/Syntax/SeqSyntax.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1-
using Seq.Syntax.Expressions;
1+
using System.Diagnostics.CodeAnalysis;
2+
using Seq.Syntax.Expressions;
23

34
namespace SeqCli.Syntax;
45

56
static class SeqSyntax
67
{
78
public static CompiledExpression CompileExpression(string expression)
89
{
9-
return SerilogExpression.Compile(expression);
10+
return SerilogExpression.Compile(expression, nameResolver: new SeqCliNameResolver());
11+
}
12+
}
13+
14+
class SeqCliNameResolver: NameResolver
15+
{
16+
public override bool TryResolveBuiltInPropertyName(string alias, [MaybeNullWhen(false)] out string target)
17+
{
18+
switch (alias)
19+
{
20+
case "@l":
21+
target = "coalesce(SeqCliOriginalLevel, @l)";
22+
return true;
23+
default:
24+
target = null;
25+
return false;
26+
}
1027
}
1128
}

0 commit comments

Comments
 (0)