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

Add ability to read ANSI escape codes from logs #57

Closed
ssbarnea opened this issue May 31, 2018 · 12 comments
Closed

Add ability to read ANSI escape codes from logs #57

ssbarnea opened this issue May 31, 2018 · 12 comments

Comments

@ssbarnea
Copy link

Some logs files already have ANSI coloring on them and it would be great it this extension would be able to deal with them instead of displaying the ugly ANSI escapes.

@emilast
Copy link
Owner

emilast commented Jun 4, 2018

Thanks for this suggestion. I have actually never seen a log file like that and I'm not sure of how it could be implemented. But I'll leave the issue open so that someone can contribute if they think of a good solution to this problem.

@ssbarnea
Copy link
Author

ssbarnea commented Jun 5, 2018

@emilast There is are some reasons why you didn't see it:

  • most tools disable (ANSI) coloring when stdout is not a TTY (simple test in the code), this being a protection for allowing output stream redirection. The moment you pipe the stdout of the command to some other tool or file, it loses its TTY ability. This prevents accidents when you endup with ANSI "garbage" in the logs.
  • also most tools do have special command line switches or environment variables that allow user to tune the ANSI output behaviour between 3 variants: auto (on on tty, off without tty), forced on, forced off. Defaults depend from tool to tool.
  • once someone spots the ANSI garbage in logs they usually fix the issue by disabling ANSI on the tool or converting the output to something else, usually ansi2html.

For browsers there are extensions that can render ANSI escaped text files. As far as I know, no browser has native support for ANSI escaped files.

Apparently there is one ATOM extension that is able to do this, see https://atom.io/packages/language-ansi-styles

@tetchel
Copy link

tetchel commented Feb 2, 2019

I would love to see this. Our product has nodemon logs (usually in the VS Code Output view, but can be opened as files too) and it would be awesome to colourize those. ansi_up might be a helpful package.

@duxbuse
Copy link

duxbuse commented Feb 27, 2019

This please. A lot of the hard work differentiating parts of the log is done with ansi colour codes. Just need to colour based on the ansi encoding. Im getting this a lot from my docker-compose logs

For example the following log should have the name of the service coloured based on [32 -> [36
[0 is just normal so that should be overwritten with the current colouring from this extension.

[35mservice-orchestrator_1  |[0m                 </basedOnMessageForm>
[32mapi-tests_1             |[0m     "caseVersion": 1,
[36;1mmountebank_1          |[0m �[32minfo�[39m: [http:4591 UamService] localhost:55900 Response Sent Successfully !!
[36mintegration-tests_1     |[0m 16:27:10.424 [DEBUG] Completing Build operation
[34msimulator-so_1          |[0m                 <messageHeader>
[33mplugin-npp-api-tests_1  |[0m       at node_modules/supertest/lib/test.js:128:5
[35mservice-orchestrator_1  |[0m                 <emittedBySourceSystemInstance>
[32mapi-tests_1             |[0m     "caseType": "DEFAULT",
[36;1mmountebank_1          |[0m �[32minfo�[39m: [http:4573 GAL/PartyService] => GET /api/partyservice/parties?q=%7B%22externalId%22
[36mintegration-tests_1     |[0m 16:27:10.424 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation completed
[34msimulator-so_1          |[0m                 <sourceSystemMessageID>a69ca6fb-71f9-4054-ad8e-d408ff84fa58</sourceSystemMessageID>
[35mservice-orchestrator_1  |[0m                                 <countryCode></countryCode>
[33mplugin-npp-api-tests_1  |[0m       at Test.Request.callback (node_modules/superagent/lib/node/index.js:631:3)
[32mapi-tests_1             |[0m

@ArtemGr
Copy link

ArtemGr commented Mar 6, 2019

I have actually never seen a log file like that

Some commands allow you to test this by explicitly enabling the color escapes.
For example, ls --color > log might produce

desktop.ini
�[0m�[01;32miTunes64Setup.exe�[0m
log 

instead of

desktop.ini
iTunes64Setup.exe
log 

@ssbarnea
Copy link
Author

ssbarnea commented Mar 6, 2019

@ArtemGr Most tools are smart enough to disable ANSI sequences when the output is not a TTY (file redirection being such example). Still there are cases where ANSI enabled if forcebly enabled even if the stdout is not a tty and good example is usually a CI system that has an ANSI enabled console.

I personally would find very useful to be able to read ANSI logs. If there are any concerns about backwards compatibility this feature could be made optional.

@electrovir
Copy link

There's no extension in the VS Code marketplace (from what I can find) that does highlighting for ANSI color codes. This extension seems to be the most relevant though; it would be a killer feature for me!

@foton
Copy link

foton commented Jul 24, 2020

There's no extension in the VS Code marketplace (from what I can find) that does highlighting for ANSI color codes. This extension seems to be the most relevant though; it would be a killer feature for me!

Maybe this help (set file type at right bottom as VT100): https://marketplace.visualstudio.com/items?itemName=Tobias-Faller.vt100-syntax-highlighting

@mihaibrana
Copy link

Thanks @foton that really helps :). That's exactly what I'd love this extension to do. I would say such a features falls in the area of working with log files in a better way. Perhaps it could even by done by default when detecting some ANSI codes, or by way of configuration. In any case, the extension @foton found could perhaps be a source of inspiration for adding this feature in this one.

https://github.com/TobiasFaller/vscode-vt100-syntax-highlight

@aishfenton
Copy link

I'd say it's pretty common for logs to include some Ansi color codes (in particular unit test outputs). Kind of surprised to see it wasn't already supported (since standard bash tools like Less already do with -R).

@nam20485
Copy link

There is now a very nice extension to do this.

ANSI Colors extension

And don't forget to open the preview or run the preview command to actually view it correctly!

@emilast
Copy link
Owner

emilast commented Jun 9, 2022

@nam20485, thank you for mentioning this other extension. I will close this issue now that there is a solution for showing ANSI colors.

@emilast emilast closed this as completed Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants