forked from redboxllc/stackdriver-serilog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update README, change namespace/package
- Loading branch information
Showing
11 changed files
with
168 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 21 additions & 21 deletions
42
...s/Redbox.Serilog.Stackdriver.Tests.csproj → ...Raileasy.Serilog.Stackdriver.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> | ||
<PackageReference Include="xunit" Version="2.4.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> | ||
<PackageReference Include="coverlet.collector" Version="1.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Redbox.Serilog.Stackdriver\Redbox.Serilog.Stackdriver.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> | ||
<PackageReference Include="xunit" Version="2.4.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> | ||
<PackageReference Include="coverlet.collector" Version="1.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Raileasy.Serilog.Stackdriver\Raileasy.Serilog.Stackdriver.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
210 changes: 105 additions & 105 deletions
210
...driver.Tests/StackdriverFormatterTests.cs → ...driver.Tests/StackdriverFormatterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,105 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Newtonsoft.Json; | ||
using Serilog.Events; | ||
using Serilog.Parsing; | ||
using Xunit; | ||
|
||
namespace Redbox.Serilog.Stackdriver.Tests | ||
{ | ||
public class StackdriverFormatterTests | ||
{ | ||
private static readonly DateTimeOffset DateTimeOffset = DateTimeOffset.Now; | ||
|
||
[Fact] | ||
public void Test_StackdriverFormatter_Format() | ||
{ | ||
var propertyName = "greeting"; | ||
var propertyValue = "hello"; | ||
var logEvent = new LogEvent(DateTimeOffset, LogEventLevel.Debug, new Exception(), | ||
new MessageTemplate("{greeting}", | ||
new MessageTemplateToken[] { new PropertyToken(propertyName, propertyValue, "l") }), | ||
new LogEventProperty[0]); | ||
|
||
using var writer = new StringWriter(); | ||
new StackdriverJsonFormatter().Format(logEvent, writer); | ||
var logDict = GetLogLineAsDictionary(writer.ToString()); | ||
|
||
AssertValidLogLine(logDict); | ||
Assert.True(logDict["message"] == propertyValue); | ||
} | ||
|
||
[Fact] | ||
public void Test_StackdrvierFormatter_FormatLong() | ||
{ | ||
// Creates a large string > 200kb | ||
var token = new TextToken(new string('*', 51200)); | ||
var logEvent = new LogEvent(DateTimeOffset, LogEventLevel.Debug, | ||
new Exception(), new MessageTemplate("{0}", new MessageTemplateToken[] { token }), | ||
new LogEventProperty[0]); | ||
|
||
using var writer = new StringWriter(); | ||
new StackdriverJsonFormatter().Format(logEvent, writer); | ||
var lines = SplitLogLogs(writer.ToString()); | ||
|
||
// The log created was longer than Stackdriver's soft limit of 256 bytes | ||
// This means the json will be spread out onto two lines, breaking search | ||
// In this scenario the library should add an additional log event informing | ||
// the user of this issue | ||
Assert.True(lines.Length == 2); | ||
// Validate each line is valid json | ||
var ourLogLineDict = GetLogLineAsDictionary(lines[0]); | ||
AssertValidLogLine(ourLogLineDict); | ||
var errorLogLineDict = GetLogLineAsDictionary(lines[1]); | ||
AssertValidLogLine(errorLogLineDict, hasException: false); | ||
} | ||
|
||
private string[] SplitLogLogs(string logLines) | ||
{ | ||
return logLines.Split("\n").Where(l => !string.IsNullOrWhiteSpace(l)).ToArray(); | ||
} | ||
|
||
/// <summary> | ||
/// Gets a log line in json format as a dictionary of string pairs | ||
/// </summary> | ||
/// <param name="log"></param> | ||
/// <returns></returns> | ||
private Dictionary<string, string> GetLogLineAsDictionary(string log) | ||
{ | ||
return JsonConvert.DeserializeObject<Dictionary<string, string>>(log); | ||
} | ||
|
||
/// <summary> | ||
/// Asserts required fields in log output are set and have valid values | ||
/// </summary> | ||
/// <param name="logDict"></param> | ||
/// <param name="hasException"></param> | ||
private void AssertValidLogLine(Dictionary<string, string> logDict, | ||
bool hasException = true) | ||
{ | ||
Assert.True(logDict.ContainsKey("message")); | ||
Assert.NotEmpty(logDict["message"]); | ||
|
||
Assert.True(logDict.ContainsKey("timestamp")); | ||
var timestamp = DateTimeOffset.UtcDateTime.ToString("O"); | ||
Assert.Equal(logDict["timestamp"], timestamp); | ||
|
||
Assert.True(logDict.ContainsKey("fingerprint")); | ||
Assert.NotEmpty(logDict["fingerprint"]); | ||
|
||
Assert.True(logDict.ContainsKey("severity")); | ||
Assert.NotEmpty(logDict["severity"]); | ||
|
||
Assert.True(logDict.ContainsKey(("MessageTemplate"))); | ||
Assert.NotEmpty(logDict["MessageTemplate"]); | ||
|
||
if (hasException) | ||
{ | ||
Assert.True(logDict.ContainsKey("exception")); | ||
Assert.NotEmpty(logDict["exception"]); | ||
} | ||
} | ||
} | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Newtonsoft.Json; | ||
using Serilog.Events; | ||
using Serilog.Parsing; | ||
using Xunit; | ||
|
||
namespace Raileasy.Serilog.Stackdriver.Tests | ||
{ | ||
public class StackdriverFormatterTests | ||
{ | ||
private static readonly DateTimeOffset DateTimeOffset = DateTimeOffset.Now; | ||
|
||
[Fact] | ||
public void Test_StackdriverFormatter_Format() | ||
{ | ||
var propertyName = "greeting"; | ||
var propertyValue = "hello"; | ||
var logEvent = new LogEvent(DateTimeOffset, LogEventLevel.Debug, new Exception(), | ||
new MessageTemplate("{greeting}", | ||
new MessageTemplateToken[] { new PropertyToken(propertyName, propertyValue, "l") }), | ||
new LogEventProperty[0]); | ||
|
||
using var writer = new StringWriter(); | ||
new StackdriverJsonFormatter().Format(logEvent, writer); | ||
var logDict = GetLogLineAsDictionary(writer.ToString()); | ||
|
||
AssertValidLogLine(logDict); | ||
Assert.True(logDict["message"] == propertyValue); | ||
} | ||
|
||
[Fact] | ||
public void Test_StackdrvierFormatter_FormatLong() | ||
{ | ||
// Creates a large string > 200kb | ||
var token = new TextToken(new string('*', 51200)); | ||
var logEvent = new LogEvent(DateTimeOffset, LogEventLevel.Debug, | ||
new Exception(), new MessageTemplate("{0}", new MessageTemplateToken[] { token }), | ||
new LogEventProperty[0]); | ||
|
||
using var writer = new StringWriter(); | ||
new StackdriverJsonFormatter().Format(logEvent, writer); | ||
var lines = SplitLogLogs(writer.ToString()); | ||
|
||
// The log created was longer than Stackdriver's soft limit of 256 bytes | ||
// This means the json will be spread out onto two lines, breaking search | ||
// In this scenario the library should add an additional log event informing | ||
// the user of this issue | ||
Assert.True(lines.Length == 2); | ||
// Validate each line is valid json | ||
var ourLogLineDict = GetLogLineAsDictionary(lines[0]); | ||
AssertValidLogLine(ourLogLineDict); | ||
var errorLogLineDict = GetLogLineAsDictionary(lines[1]); | ||
AssertValidLogLine(errorLogLineDict, hasException: false); | ||
} | ||
|
||
private string[] SplitLogLogs(string logLines) | ||
{ | ||
return logLines.Split("\n").Where(l => !string.IsNullOrWhiteSpace(l)).ToArray(); | ||
} | ||
|
||
/// <summary> | ||
/// Gets a log line in json format as a dictionary of string pairs | ||
/// </summary> | ||
/// <param name="log"></param> | ||
/// <returns></returns> | ||
private Dictionary<string, string> GetLogLineAsDictionary(string log) | ||
{ | ||
return JsonConvert.DeserializeObject<Dictionary<string, string>>(log); | ||
} | ||
|
||
/// <summary> | ||
/// Asserts required fields in log output are set and have valid values | ||
/// </summary> | ||
/// <param name="logDict"></param> | ||
/// <param name="hasException"></param> | ||
private void AssertValidLogLine(Dictionary<string, string> logDict, | ||
bool hasException = true) | ||
{ | ||
Assert.True(logDict.ContainsKey("message")); | ||
Assert.NotEmpty(logDict["message"]); | ||
|
||
Assert.True(logDict.ContainsKey("timestamp")); | ||
var timestamp = DateTimeOffset.UtcDateTime.ToString("O"); | ||
Assert.Equal(logDict["timestamp"], timestamp); | ||
|
||
Assert.True(logDict.ContainsKey("fingerprint")); | ||
Assert.NotEmpty(logDict["fingerprint"]); | ||
|
||
Assert.True(logDict.ContainsKey("severity")); | ||
Assert.NotEmpty(logDict["severity"]); | ||
|
||
Assert.True(logDict.ContainsKey(("MessageTemplate"))); | ||
Assert.NotEmpty(logDict["MessageTemplate"]); | ||
|
||
if (hasException) | ||
{ | ||
Assert.True(logDict.ContainsKey("exception")); | ||
Assert.NotEmpty(logDict["exception"]); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 24 additions & 23 deletions
47
...kdriver/Redbox.Serilog.Stackdriver.csproj → ...river/Raileasy.Serilog.Stackdriver.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<PackageId>Redbox.Serilog.Stackdriver</PackageId> | ||
<Authors>Redbox</Authors> | ||
<Description>A Serilog Formatter for Stackdriver using JSON logs</Description> | ||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> | ||
<Copyright>Copyright 2019 (c) Redbox Automated Retail, LLC</Copyright> | ||
<PackageTags>serilog stackdriver json log logging google</PackageTags> | ||
<RepositoryUrl>https://github.com/redboxllc/stackdriver-serilog.git</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" /> | ||
<PackageReference Include="Serilog.Formatting.Compact" Version="2.0.0" /> | ||
</ItemGroup> | ||
|
||
|
||
|
||
</Project> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<PackageId>Raileasy.Serilog.Stackdriver</PackageId> | ||
<Authors>Redbox</Authors> | ||
<Description>A Serilog Formatter for Stackdriver using JSON logs</Description> | ||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> | ||
<Copyright>Copyright 2019 (c) Redbox Automated Retail, LLC</Copyright> | ||
<PackageTags>serilog stackdriver json log logging google</PackageTags> | ||
<RepositoryUrl>https://github.com/raileasyuk/stackdriver-serilog.git</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> | ||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" /> | ||
<PackageReference Include="Serilog.Formatting.Compact" Version="1.0.0" /> | ||
</ItemGroup> | ||
|
||
|
||
|
||
</Project> |
Oops, something went wrong.