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

Support for ANSI color codes #4

Closed
nefarius opened this issue Feb 14, 2024 · 14 comments
Closed

Support for ANSI color codes #4

nefarius opened this issue Feb 14, 2024 · 14 comments
Assignees
Labels
enhancement New feature or request

Comments

@nefarius
Copy link

nefarius commented Feb 14, 2024

No description provided.

@amorey amorey self-assigned this Feb 14, 2024
@nefarius
Copy link
Author

For example this is how it gets interpreted in Windows Terminal:

image

@kubetail-org kubetail-org deleted a comment from linear bot Feb 14, 2024
@nodesocket
Copy link

👍🏻 adding colors. There are some great JS libs for this which should make it fairly straightforward.

@amorey
Copy link
Member

amorey commented Feb 14, 2024

Can you recommend any in particular?

@nodesocket
Copy link

Maybe this one? https://github.com/drudru/ansi_up

amorey added a commit that referenced this issue Feb 20, 2024
* Uses `ansi-html-community` package to convert messages with ansi color
codes to HTML (#4)
@amorey amorey closed this as completed Feb 20, 2024
@amorey
Copy link
Member

amorey commented Feb 20, 2024

I just published a new version (0.1.5) that adds support for ANSI color codes. To maintain the visual connection to the container color, lines that have ANSI codes will get prefaced with a color-coded dot. Check it out and let me know what you think:

helm repo update kubetail
helm upgrade kubetail kubetail/kubetail --namespace kubetail

@nefarius
Copy link
Author

Hm, just tested it, do I need to change some setting or similar, it is not happy about what my services spit out:

image

Update went through:

helm ls -a -n kubetail
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
kubetail        kubetail        7               2024-02-20 12:07:00.3693052 +0100 CET   deployed        kubetail-0.2.3  0.1.5

@amorey
Copy link
Member

amorey commented Feb 20, 2024

Hmm... sorry about that. You shouldn't have to change anything. It looks like it detected ANSI but the HTML conversion didn't go through properly. Can you send me a (sanitized) example of one of your original log lines? I'll do more testing on my end too.

@amorey amorey reopened this Feb 20, 2024
@nefarius
Copy link
Author

I've attached an anonymized log snippet produced via:

kubectl logs -lapp=my-deployment --all-containers=true | Out-File -Encoding utf8 -FilePath d:\colored-logs.txt

So I hope it got preserved as kubetail would receive it as well: colored-logs.txt

@amorey
Copy link
Member

amorey commented Feb 20, 2024

Thanks! The encoding was preserved. Will take a look.

amorey added a commit that referenced this issue Feb 20, 2024
…14)

* Replaced `ansi-html-community` library with `ansi-to-html` to convert
ansi encodings in log messages to html (#4)
* Changed method of adding log messages to DOM from `innerHTML` to
`textContent` to protect against injection attacks
@amorey
Copy link
Member

amorey commented Feb 20, 2024

Ok, just pushed a new version with a bug fix (0.1.6). Here's an example on the demo site:
https://demo.kubetail.com/console?source=deployments%2Fkubetail-demo%2Floggen-ansi

Let me know if that fixes the problem.

@nefarius
Copy link
Author

Well, partial good news! We have readable text back, however now no colors at all 😅 Guess this is not how it's supposed to be?

image

@nefarius
Copy link
Author

nefarius commented Feb 20, 2024

Sorry for that extra noise added by extensions; I also tried it in a private window with no extensions so nothing is interfering.

EDIT: fresh Firefox Portable also color-less.

amorey added a commit that referenced this issue Feb 21, 2024
* Switched ansi parsing library to `ansi_up` to supports more ansi
encodings (#4)
* Using dark background for ansi-encoded messages
@amorey amorey closed this as completed Feb 21, 2024
@amorey
Copy link
Member

amorey commented Feb 21, 2024

The latest release (0.1.7) should help but there's still work to be done. I switched to the ansi_up package which supports more ANSI codes but it assumes a dark background so for now I made the background of the message column dark when ANSI encodings are found:

Kubetail___Log_Viewer

https://demo.kubetail.com/console?source=deployments%2Fkubetail-demo%2Floggen-ansi

Let me know if the ANSI encodings are being handled correctly on your end. I'll create another issue to track further improvements to ANSI handling.

@nefarius
Copy link
Author

Yes! Looks exactly like on the terminal now, great work, thanks a ton!

@amorey amorey added the enhancement New feature or request label Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants