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

Conversation

mkhamoyan
Copy link
Contributor

@mkhamoyan mkhamoyan commented Aug 22, 2022

Microsoft.Extensions.Logging.Console.LoggerColorBehavior.Default
- Use the default color behavior, enabling color except when the console output is redirected.

Default case should behave as enabled in this test case.
Fix #50575 and #51398

@ghost
Copy link

ghost commented Aug 22, 2022

Tagging subscribers to this area: @dotnet/area-extensions-logging
See info in area-owners.md if you want to be subscribed.

Issue Details
Use the default color behavior, enabling color except when the console output is redirected. Enables color except when the console output is redirected. Default case should behave as enabled in this test case. Fix #50575 and #51398
Author: mkhamoyan
Assignees: -
Labels:

area-Extensions-Logging

Milestone: -

@mkhamoyan
Copy link
Contributor Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@tarekgh
Copy link
Member

tarekgh commented Aug 22, 2022

@mkhamoyan the test you are changing is failing the CI. Maybe it is better to fix it for Android and Apple OS's only?

@mkhamoyan
Copy link
Contributor Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mkhamoyan
Copy link
Contributor Author

@mkhamoyan the test you are changing is failing the CI. Maybe it is better to fix it for Android and Apple OS's only?

Totally forgot about other platforms :) Fixed it!

@mkhamoyan mkhamoyan merged commit ad366f2 into dotnet:main Aug 23, 2022
@mkhamoyan mkhamoyan deleted the 50575_fix_test branch August 23, 2022 12:44
@@ -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.

mkhamoyan added a commit that referenced this pull request Aug 24, 2022
mkhamoyan added a commit that referenced this pull request Aug 24, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Sep 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Microsoft.Extensions.Logging.Console.Tests fail on Android
5 participants