Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up unused level property #307

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/SeqCli/Cli/Commands/IngestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ protected override async Task<int> Run()
try
{
var enrichers = new List<ILogEventEnricher>();

if (_level != null)
enrichers.Add(new ScalarPropertyEnricher(LevelMapping.SurrogateLevelProperty, _level));

foreach (var (name, value) in _properties.Properties)
enrichers.Add(new ScalarPropertyEnricher(name, value));

Expand Down
4 changes: 2 additions & 2 deletions src/SeqCli/PlainText/LogEvents/LogEventBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static LogEvent FromProperties(IDictionary<string, object?> properties, s
var messageTemplate = GetMessageTemplate(properties);
var traceId = GetTraceId(properties);
var spanId = GetSpanId(properties);
var props = GetLogEventProperties(properties, remainder, level);
var props = GetLogEventProperties(properties, remainder);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This level is no longer needed; it would tack the surrogate level property on, but we do this while reading now.


var fallbackMappedLevel = level != null ? LevelMapping.ToSerilogLevel(level) : LogEventLevel.Information;
properties[LevelMapping.SurrogateLevelProperty] = level;
Expand Down Expand Up @@ -100,7 +100,7 @@ static MessageTemplate GetMessageTemplate(IDictionary<string, object?> propertie
return null;
}

static IEnumerable<LogEventProperty> GetLogEventProperties(IDictionary<string, object?> properties, string? remainder, string? level)
static IEnumerable<LogEventProperty> GetLogEventProperties(IDictionary<string, object?> properties, string? remainder)
{
var payload = properties
.Where(p => !ReifiedProperties.IsReifiedProperty(p.Key))
Expand Down
26 changes: 26 additions & 0 deletions test/SeqCli.EndToEnd/Ingest/OverrideLevelIngestionTestCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Seq.Api;
using SeqCli.EndToEnd.Support;
using Serilog;
using Xunit;

namespace SeqCli.EndToEnd.Ingest;

public class OverrideLevelIngestionTestCase : ICliTestCase
{
public async Task ExecuteAsync(
SeqConnection connection,
ILogger logger,
CliCommandRunner runner)
{
var inputFiles = Path.Combine("Data", "log-*.txt");

var exit = runner.Exec("ingest", $"-i {inputFiles} -l OK");
Assert.Equal(0, exit);

var events = await connection.Events.ListAsync();
Assert.Equal(4, events.Count(e => e.Level == "OK"));
}
}