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

#50575 default case color behaviour is enabled #74349

Merged
merged 4 commits into from
Aug 23, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class SimpleConsoleFormatterTests : ConsoleFormatterTests
[InlineData(LoggerColorBehavior.Default)]
[InlineData(LoggerColorBehavior.Enabled)]
[InlineData(LoggerColorBehavior.Disabled)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/50575", TestPlatforms.Android)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51398", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
[ActiveIssue("https://github.com/dotnet/runtime/issues/73436", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void Log_WritingScopes_LogsWithCorrectColorsWhenColorEnabled(LoggerColorBehavior colorBehavior)
{
Expand All @@ -34,6 +32,9 @@ public void Log_WritingScopes_LogsWithCorrectColorsWhenColorEnabled(LoggerColorB
logger.Log(LogLevel.Information, 0, _state, null, _defaultFormatter);
}

// For Android/iOS/tvOS/MacCatalyst default color behavior, enables the color
colorBehavior = colorBehavior == LoggerColorBehavior.Default && (PlatformDetection.IsAndroid || PlatformDetection.IsAppleMobile) ? LoggerColorBehavior.Enabled : colorBehavior;
Copy link
Member

Choose a reason for hiding this comment

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

Why is the color enabled by default on Android and Apple?

Copy link
Contributor Author

@mkhamoyan mkhamoyan Aug 23, 2022

Choose a reason for hiding this comment

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

From documentation LoggerColorBehavior.Default means color is not enabled when the console output is redirected.
In case of Android/Apple it was enabled which I'm assuming means console output is not redirected on this platforms.
https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Logging.Console/src/SimpleConsoleFormatter.cs#L160
https://github.com/dotnet/runtime/blob/main/src/libraries/Common/src/System/Console/ConsoleUtils.cs#L31

Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't be outputting color codes for Android or the Apple mobile platforms, they have no shell* and all the output gets redirected to some log file.

(*) Android kinda does via adb shell, but it's not meant for running apps.

Copy link
Member

@tarekgh tarekgh Aug 23, 2022

Choose a reason for hiding this comment

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

Is the issue here Console.IsOutputRedirected behave differently between Android/Apple Mobile than other platforms? If this is the case, the line https://source.dot.net/#Microsoft.Extensions.Logging.Console/SimpleConsoleFormatter.cs,161 will need to be fixed for Android and Apple mobile I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will revert this PR and create new one.


// Assert
switch (colorBehavior)
{
Expand Down