Skip to content

Commit

Permalink
Merge pull request #317 from datalust/dev
Browse files Browse the repository at this point in the history
2024.1 Maintenance Release
  • Loading branch information
nblumhardt authored Jan 30, 2024
2 parents 11a4a0f + 7ee8bb6 commit c8cc16d
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 25 deletions.
6 changes: 4 additions & 2 deletions src/SeqCli/Apps/AppLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Linq;
using System.Reflection;
using Seq.Apps;
using Seq.Syntax.Expressions;
using Serilog;

namespace SeqCli.Apps;
Expand All @@ -30,10 +31,11 @@ class AppLoader : IDisposable
// These are used for interop between the host process and the app. The
// app _must_ be able to load on the unified version.
readonly Assembly[] _contracts =
{
[
typeof(SeqApp).Assembly,
typeof(Log).Assembly,
};
typeof(SerilogExpression).Assembly
];

public AppLoader(string packageBinaryPath)
{
Expand Down
3 changes: 1 addition & 2 deletions src/SeqCli/Cli/Commands/IngestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
using Serilog;
using Serilog.Core;
using Serilog.Events;
using Serilog.Expressions;

namespace SeqCli.Cli.Commands;

Expand Down Expand Up @@ -95,7 +94,7 @@ protected override async Task<int> Run()
if (_filter != null)
{
var eval = SeqSyntax.CompileExpression(_filter);
filter = evt => ExpressionResult.IsTrue(eval(evt));
filter = evt => Seq.Syntax.Expressions.ExpressionResult.IsTrue(eval(evt));
}

var connection = _connectionFactory.Connect(_connection);
Expand Down
11 changes: 10 additions & 1 deletion src/SeqCli/Cli/Commands/PrintCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.IO;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Seq.Syntax.Expressions;
using SeqCli.Cli.Features;
using SeqCli.Config;
using SeqCli.Ingestion;
Expand Down Expand Up @@ -81,7 +82,15 @@ var theme
applyThemeToRedirectedOutput: applyThemeToRedirectedOutput);

if (_filter != null)
outputConfiguration.Filter.ByIncludingOnly(_filter);
{
if (!SerilogExpression.TryCompile(_filter, out var filter, out var error))
{
Log.Error("The specified filter could not be compiled: {Error}", error);
return 1;
}

outputConfiguration.Filter.ByIncludingOnly(evt => ExpressionResult.IsTrue(filter(evt)));
}

await using var logger = outputConfiguration.CreateLogger();
foreach (var input in _fileInputFeature.OpenInputs())
Expand Down
3 changes: 3 additions & 0 deletions src/SeqCli/Output/OutputFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace SeqCli.Output;

static class OutputFormatter
{
// This is the only usage of Serilog.Expressions remaining in seqcli; the upstream Seq.Syntax doesn't yet support
// the `@sp` property, because it needs to load on older Seq installs with older Serilog versions embedded in the
// app runner. Once we've updated it, we can switch this to a Seq.Syntax template.
internal static readonly ITextFormatter Json = new ExpressionTemplate(
$"{{ {{@t, @mt, @l: coalesce({LevelMapping.SurrogateLevelProperty}, if @l = 'Information' then undefined() else @l), @x, @sp, @tr, @ps: coalesce({TraceConstants.ParentSpanIdProperty}, @ps), @st: coalesce({TraceConstants.SpanStartTimestampProperty}, @st), ..rest()}} }}\n"
);
Expand Down
2 changes: 1 addition & 1 deletion src/SeqCli/SeqCli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<PackageReference Include="Destructurama.JsonNet" Version="2.0.1" />
<PackageReference Include="newtonsoft.json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="serilog.expressions" Version="4.0.0" />
<PackageReference Include="Serilog.Expressions" Version="4.0.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="2.0.0" />
<PackageReference Include="Serilog.Formatting.Compact.Reader" Version="3.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
Expand Down
20 changes: 20 additions & 0 deletions src/SeqCli/Syntax/SeqCliNameResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Diagnostics.CodeAnalysis;
using Seq.Syntax.Expressions;

namespace SeqCli.Syntax;

class SeqCliNameResolver: NameResolver
{
public override bool TryResolveBuiltInPropertyName(string alias, [MaybeNullWhen(false)] out string target)
{
switch (alias)
{
case "@l":
target = "coalesce(SeqCliOriginalLevel, @l)";
return true;
default:
target = null;
return false;
}
}
}
21 changes: 2 additions & 19 deletions src/SeqCli/Syntax/SeqSyntax.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Seq.Syntax.Expressions;
using Seq.Syntax.Expressions;

namespace SeqCli.Syntax;

Expand All @@ -9,20 +8,4 @@ public static CompiledExpression CompileExpression(string expression)
{
return SerilogExpression.Compile(expression, nameResolver: new SeqCliNameResolver());
}
}

class SeqCliNameResolver: NameResolver
{
public override bool TryResolveBuiltInPropertyName(string alias, [MaybeNullWhen(false)] out string target)
{
switch (alias)
{
case "@l":
target = "coalesce(SeqCliOriginalLevel, @l)";
return true;
default:
target = null;
return false;
}
}
}
}

0 comments on commit c8cc16d

Please sign in to comment.