Skip to content
Draft
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
22 changes: 21 additions & 1 deletion src/Sentry/Internal/DefaultSentryStructuredLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@
var scope = _hub.GetScope();
log.SetDefaultAttributes(_options, scope?.Sdk ?? SdkVersion.Instance);

CaptureLog(log);
var captured = CaptureLog(log);

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / Build (net9.0)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / Build (net9.0)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / Build (net9.0)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / Build (net9.0)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-musl-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / Trim analysis

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (linux-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / Analyze

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / Analyze

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / Analyze

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / Analyze

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / Analyze

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / Analyze

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / Analyze

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / Analyze

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / Analyze

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / Analyze

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / ios-tests

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / ios-tests

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / ios-tests

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / ios-tests

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-x64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (win-arm64)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / MSBuild

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / MSBuild

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / MSBuild

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / MSBuild

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / MSBuild

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / MSBuild

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / MSBuild

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / MSBuild

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Cannot assign void to an implicitly-typed variable

Check failure on line 74 in src/Sentry/Internal/DefaultSentryStructuredLogger.cs

View workflow job for this annotation

GitHub Actions / .NET (macos)

Cannot assign void to an implicitly-typed variable

if (captured && _options.Debug)
{
WriteToConsole(log);
}
}

/// <inheritdoc />
Expand Down Expand Up @@ -109,4 +114,19 @@
{
_batchProcessor.Dispose();
}

private static void WriteToConsole(SentryLog log)
{
Debug.Assert(!log.TryGetAttribute("sentry.origin", out string? origin), $"Logs should only be printed to the Console when captured via the Sentry Logger APIs and not through any integration: {origin}");

var capacity = 10 + 2 + log.Message.Length;
var text = new StringBuilder(capacity);
text.Append(log.Level.ToText().PadLeft(10));
text.Append(": ");
text.Append(log.Message);

Debug.Assert(text.Length == capacity, $"Wrong assumption of capacity: Expected: {capacity}; Actual: {text.Length}");

Console.WriteLine(text.ToString());
}
}
21 changes: 21 additions & 0 deletions src/Sentry/SentryLogLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,25 @@ static SentryLogLevel Overflow(int value, IDiagnosticLogger? logger)
return SentryLogLevel.Fatal;
}
}

internal static string ToText(this SentryLogLevel level)
{
return (int)level switch
{
<= 0 => "trace(<1)",
1 => "trace",
>= 2 and <= 4 => $"trace({(int)level})",
5 => "debug",
>= 6 and <= 8 => $"debug({(int)level})",
9 => "info",
>= 10 and <= 12 => $"info({(int)level})",
13 => "warn",
>= 14 and <= 16 => $"warn({(int)level})",
17 => "error",
>= 18 and <= 20 => $"error({(int)level})",
21 => "fatal",
>= 22 and <= 24 => $"fatal({(int)level})",
>= 25 => "fatal(>24)",
};
}
}
44 changes: 44 additions & 0 deletions test/Sentry.Tests/SentryLogLevelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,48 @@ public static TheoryData<int, SentryLogLevel> Create()
{ 24, SentryLogLevel.Fatal },
};
}

[Theory]
[MemberData(nameof(Convert))]
public void Convert_FromSentryLogLevel_ToString(int level, string expected)
{
var @enum = (SentryLogLevel)level;

var actual = @enum.ToText();

Assert.Equal(expected, actual);
}

public static TheoryData<int, string> Convert()
{
return new TheoryData<int, string>
{
{ 0, "trace(<1)" },
{ 1, "trace" },
{ 2, "trace(2)" },
{ 3, "trace(3)" },
{ 4, "trace(4)" },
{ 5, "debug" },
{ 6, "debug(6)" },
{ 7, "debug(7)" },
{ 8, "debug(8)" },
{ 9, "info" },
{ 10, "info(10)" },
{ 11, "info(11)" },
{ 12, "info(12)" },
{ 13, "warn" },
{ 14, "warn(14)" },
{ 15, "warn(15)" },
{ 16, "warn(16)" },
{ 17, "error" },
{ 18, "error(18)" },
{ 19, "error(19)" },
{ 20, "error(20)" },
{ 21, "fatal" },
{ 22, "fatal(22)" },
{ 23, "fatal(23)" },
{ 24, "fatal(24)" },
{ 25, "fatal(>24)" },
};
}
}
Loading