Skip to content

Commit 534840e

Browse files
committed
Level label is excluded by default
1 parent 8787f40 commit 534840e

14 files changed

+63
-12
lines changed

src/Serilog.Sinks.Grafana.Loki/LoggerConfigurationLokiExtensions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ public static class LoggerConfigurationLokiExtensions
7979
/// A custom <see cref="ILokiHttpClient"/> implementation. Default value is
8080
/// <see cref="LokiHttpClient"/>.
8181
/// </param>
82+
/// <param name="createLevelLabel">
83+
/// Should level label be created. Default value is false
84+
/// The level label always won't be created while using <see cref="ILabelAwareTextFormatter"/>
85+
/// </param>
8286
/// <returns>Logger configuration, allowing configuration to continue.</returns>
8387
public static LoggerConfiguration GrafanaLoki(
8488
this LoggerSinkConfiguration sinkConfiguration,
@@ -93,14 +97,15 @@ public static LoggerConfiguration GrafanaLoki(
9397
int? queueLimit = null,
9498
TimeSpan? period = null,
9599
ITextFormatter? textFormatter = null,
96-
ILokiHttpClient? httpClient = null)
100+
ILokiHttpClient? httpClient = null,
101+
bool createLevelLabel = false)
97102
{
98103
if (sinkConfiguration == null)
99104
{
100105
throw new ArgumentNullException(nameof(sinkConfiguration));
101106
}
102107

103-
var createLevelLabel = textFormatter is not ILabelAwareTextFormatter {ExcludeLevelLabel: true};
108+
createLevelLabel = createLevelLabel && textFormatter is not ILabelAwareTextFormatter {ExcludeLevelLabel: true};
104109
var batchFormatter = new LokiBatchFormatter(labels, filtrationMode, filtrationLabels, createLevelLabel);
105110

106111
period ??= TimeSpan.FromSeconds(1);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"streams":[{"stream":{},"values":[["<unixepochinnanoseconds>","This is an information without params"],["<unixepochinnanoseconds>","This is an error without params"]]}]}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"streams":[{"stream":{"level":"error"},"values":[["<unixepochinnanoseconds>","[ERR] An error occured"]]}]}
1+
{"streams":[{"stream":{},"values":[["<unixepochinnanoseconds>","[ERR] An error occured"]]}]}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"streams":[{"stream":{"level":"error","server_name":"loki_test"},"values":[["<unixepochinnanoseconds>","An error occured"]]}]}
1+
{"streams":[{"stream":{"server_name":"loki_test"},"values":[["<unixepochinnanoseconds>","An error occured"]]}]}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"streams":[{"stream":{"server_ip":"127.0.0.1","level":"error"},"values":[["<unixepochinnanoseconds>","An error occured"]]}]}
1+
{"streams":[{"stream":{"server_ip":"127.0.0.1"},"values":[["<unixepochinnanoseconds>","An error occured"]]}]}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"streams":[{"stream":{"level":"info","Param-0":"Namespace.Module.Method"},"values":[["<unixepochinnanoseconds>","An error occured in \u0022Namespace.Module.Method\u0022"]]}]}
1+
{"streams":[{"stream":{"Param-0":"Namespace.Module.Method"},"values":[["<unixepochinnanoseconds>","An error occured in \u0022Namespace.Module.Method\u0022"]]}]}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"streams":[{"stream":{"level":"error"},"values":[["<unixepochinnanoseconds>","An error occured"]]}]}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"streams":[{"stream":{"level":"error","server_ip":"127.0.0.1"},"values":[["<unixepochinnanoseconds>","An error occured"]]}]}
1+
{"streams":[{"stream":{"server_ip":"127.0.0.1"},"values":[["<unixepochinnanoseconds>","An error occured"]]}]}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"streams":[{"stream":{"level":"info"},"values":[["<unixepochinnanoseconds>","What is the meaning of life?"]]},{"stream":{"level":"info","MeaningOfLife":"42"},"values":[["<unixepochinnanoseconds>","The meaning of life is 42"]]}]}
1+
{"streams":[{"stream":{},"values":[["<unixepochinnanoseconds>","What is the meaning of life?"]]},{"stream":{"MeaningOfLife":"42"},"values":[["<unixepochinnanoseconds>","The meaning of life is 42"]]}]}

0 commit comments

Comments
 (0)