Aligning log columns vertically

Hi everybody!
I need to align log fields vertically on a log dashboard. In my case, since the 3rd field differs on length, message strings are not aligned.
At first I thought I can make it through regex but there’s no way to do that without getting the length of the string. So, I guess we need a template function for that. Or anyone have a solution, thanks a lot!
I already opened up an issue on github Template function for making string on exact length by adding space · Issue #34443 · grafana/grafana · GitHub

What I wanna achieve is something like this, just the alignments

Hey @yech
Have you considered using a Table panel instead? Do you need to use the Logs panel specifically?

As it splits the rows it’s not gonna be good on style, do you think is there a way to get string length on grafana, maybe I can try something like;
add x spaces at the end of the string,
x = (maximum length of that field) - (length of the string)
that way,
Thanks!

This is possible today!

The relevant part is here

| line_format "{{ printf \"%-20.20s\" .resource_labels_cluster_name}}\t{{printf \"%-5.5s\" .labels_authorization_k8s_io_decision}}\t{{.protoPayload_resourceName}}"

Use the printf function with line_format to force a size which can then vertically align.

It does require parsing the log line into labels with json logfmt or regexp parser so you can select the elements and how to align them.

3 Likes

Wow that’s greatt :smile:

One thing, it’s not working while “wrap lines” option is disabled. I’m disabling it for showing logs line by line. Is it something on purpose or we can fix that?

I really appreciate all your efforts :muscle:

1 Like

I can open up an issue if its something that can be fixed, anybody?

I’ve noticed this behavior before with wrapped lines, please open an issue in the Grafana repo for this.

I’m not exactly sure what can be done but it would be good to take a look!

Alright, I’ll open it, thanks!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.