kubetail-org / kubetail

Web-based, real-time log viewer for Kubernetes
https://www.kubetail.com/demo
Apache License 2.0
301 stars 16 forks source link

Support for ANSI color codes #4

Closed nefarius closed 4 months ago

nefarius commented 5 months ago

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

image

nodesocket commented 5 months ago

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

amorey commented 5 months ago

Can you recommend any in particular?

nodesocket commented 5 months ago

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

amorey commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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.

nefarius commented 4 months ago

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 commented 4 months ago

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

amorey commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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