Skip to content

Logs include control characters (in place of coloring) in Visual Studio output window when using Docker #673

Closed

Description

@mikeharder

Repro Steps

  1. Install Docker for Windows Beta and Docker Tools for Visual Studio
  2. New ASP.NET Core Application
  3. Add -> Docker Support
  4. Debug -> Start Without Debugging

Issue

Logs in output window include garbage characters in place of coloring:

DockerTask.ps1 -WaitForUrl -Machine ''
Hosting environment: Production
Content root path: /app
Now listening on: http://*:80
Application started. Press Ctrl+C to shut down.
�[0m�[32minfo�[39m�[0m�[0m�[32m: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]�[39m�[0m
      Request starting HTTP/1.1 GET http://docker/  

CC: @glennc

Activity

  1. changed the title [-]Logs include garbage characters in Visual Studio output window when using Docker[/-] [+]Logs include garbage characters in place of coloring, in Visual Studio output window when using Docker[/+] on May 18, 2016
  2. changed the title [-]Logs include garbage characters in place of coloring, in Visual Studio output window when using Docker[/-] [+]Logs include control characters (in place of coloring) in Visual Studio output window when using Docker[/+] on May 18, 2016
  3. muratg commented on May 19, 2016

    @muratg

    Not sure what's the proper way to fix this would be. Perhaps we can detect we're outputting to VS window and disable colors?

  4. nil4 commented on May 19, 2016

    @nil4

    @muratg Wouldn't it be better if VS would interpret the codes and display color output?
    The WebPack Task Runner extension by @madskristensen, for example, supports color output in a VS pane:
    WebPack colored output

  5. muratg commented on May 19, 2016

    @muratg

    @nil4 Good point!

    @BillHiebert Do you know if that's something we could do? AFAIK, npm console output has the same issue.

  6. BillHiebert commented on May 19, 2016

    @BillHiebert

    The output window does not support colors today, nor does it recognize and strip the control characters from the text. There are some extensions you can install which do add colors but I don't know if they handle the control sequences.

    Failing that, Docker tooling needs to strip the characters from the strings before sending them on to the output window.

  7. glennc commented on May 19, 2016

    @glennc

    @SteveLasker Are the tools guys thinking about this already or were you expecting something from logging?

  8. mikeharder commented on May 19, 2016

    @mikeharder
    Author

    If possible, I think we should fix this at the Logging level, so any downstream consumer is fixed. I know some tools detect whether output is going to a console or redirected (to a file or another process), and change their output format accordingly.

  9. mikeharder commented on May 19, 2016

    @mikeharder
    Author

    It can be done from .NET via the Console.IsOutputRedirected property.

  10. mikeharder commented on May 20, 2016

    @mikeharder
    Author

    I ran a simple test and redirected the output to a file, and the file didn't contain any control characters:

    var factory = new LoggerFactory();
    factory.AddConsole();
    var logger = factory.CreateLogger<Program>();
    logger.LogInformation("information");
    dotnet restore
    dotnet build
    dotnet bin\Debug\netcoreapp1.0\ConsoleApp1.dll > out.txt
    

    So maybe Logging is already doing the right thing, and this does need to be fixed downstream. I will send mail to the Docker Tools for VS team.

  11. muratg commented on May 26, 2016

    @muratg

    Putting this in 1.0.1 milestone for further investigation post RTM.

  12. mikeharder commented on May 26, 2016

    @mikeharder
    Author

    The issue is most likely in Docker Tools for VS, rather than Logging. They have filed an issue on their end and will fix it when they are able.

  13. mrgleba commented on Jun 22, 2016

    @mrgleba

    We're using this with Kestrel on mono inside docker. We're logging to the console and then we're using docker's syslog driver to forward the logs. As a result we get the string polluted by control characters.

    Maybe the simplest solution would be to include an option to disable colors altogether?

  14. muratg commented on Jul 12, 2016

    @muratg

    @mikeharder what's the current recommendation for this one?

    cc @davidfowl

  15. mikeharder commented on Jul 12, 2016

    @mikeharder
    Author

    @muratg: We should really look at end-to-end scenarios to see how they can be improved. For the scenario mentioned above:

    We're logging to the console and then we're using docker's syslog driver to forward the logs. As a result we get the string polluted by control characters.

    One option might be logging to a file instead of the console. I've verified that control characters are not present when logging to a file.

    Another option might be for docker's driver to remove control characters. I think any process which writes colors to the console would have the same issue in Docker.

    Finally, we could add an option in Logging to disable colors, but this has a few drawbacks. First, the app author may not know when or whether to disable colors. It depends on the context the app is being used. Second, other tools like the CLI would also need to add options to disable colors.

  16. BrennanConroy commented on Jul 28, 2016

    @BrennanConroy
    Member

    I'm not sure how you were even getting control characters on Windows since we don't write them unless you are on Unix. Unless our IsWindows check isn't working properly on Docker for Windows...

  17. BrennanConroy commented on Jul 29, 2016

    @BrennanConroy
    Member

    After some investigation we can't easily detect if the output is being redirected, see https://github.com/dotnet/corefx/issues/10428

  18. neybar commented on Nov 20, 2017

    @neybar

    What is the status of this? We are using docker containers on AWS, and get the control characters in our logs. Makes it rather difficult to read.

    If it is difficult to auto detect, could we get an Environment variable or some other way to just turn off colorizing?

  19. mikeharder commented on Jul 30, 2018

    @mikeharder
    Author

    As a workaround, it's possible to use the ConsoleLogger.DisableColors option added in 2.1: aspnet/Logging#772

  20. pakrym commented on Nov 15, 2018

    @pakrym

    If you are using WebHostBuilder.CreateDefault setting ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS environment variable to true would disable colors too.

  21. added this to the Backlog milestone on Dec 13, 2018
  22. ghost locked as resolved and limited conversation to collaborators on Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions