Skip to content

Commit

Permalink
updated API
Browse files Browse the repository at this point in the history
  • Loading branch information
jincod committed Oct 5, 2020
1 parent 01e980f commit c7eaa52
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/Serilog.Sinks.Loki.Example/LogLabelProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public IList<LokiLabel> GetLabels()
};
}

public bool PropertiesAsLabels { get; set; } = false;
public IList<string> PropertiesAsLabels { get; set; } = new List<string>
{
"MyPropertyName"
};
}
}
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.Loki/Labels/DefaultLogLabelProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public IList<LokiLabel> GetLabels()
return new List<LokiLabel>();
}

public bool PropertiesAsLabels { get; set; } = true;
public IList<string> PropertiesAsLabels { get; set; } = new List<string>();
}
}
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.Loki/Labels/ILogLabelProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace Serilog.Sinks.Loki.Labels
public interface ILogLabelProvider
{
IList<LokiLabel> GetLabels();
bool PropertiesAsLabels { get; set; }
IList<string> PropertiesAsLabels { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/Serilog.Sinks.Loki/LokiBatchFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Serilog.Sinks.Loki
internal class LokiBatchFormatter : IBatchFormatter
{
private readonly IList<LokiLabel> _globalLabels;
private readonly bool _propertiesAsLabels;
private readonly IList<string> _propertiesAsLabels;

public LokiBatchFormatter()
{
Expand Down Expand Up @@ -71,7 +71,7 @@ public void Format(IEnumerable<LogEvent> logEvents, ITextFormatter formatter, Te
// We also remove any \r\n newlines and replace with \n new lines to prevent "bad request" responses
// We also remove backslashes and replace with forward slashes, Loki doesn't like those either
var propertyValue = property.Value.ToString().Replace("\"", "").Replace("\r\n", "\n").Replace("\\", "/");
if (_propertiesAsLabels)
if (_propertiesAsLabels.Contains(property.Key, StringComparer.OrdinalIgnoreCase))
{
stream.Labels.Add(new LokiLabel(property.Key, propertyValue));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public IList<LokiLabel> GetLabels()
};
}

public bool PropertiesAsLabels { get; set; } = false;
public IList<string> PropertiesAsLabels { get; set; } = new List<string>();
}
}

0 comments on commit c7eaa52

Please sign in to comment.