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

Indent all keyvals #118

Open
viccon opened this issue Apr 16, 2024 · 3 comments
Open

Indent all keyvals #118

viccon opened this issue Apr 16, 2024 · 3 comments

Comments

@viccon
Copy link

viccon commented Apr 16, 2024

Hi, thanks a lot for creating this package!

I have been playing around with it a bit today, but I have not been able to find a way that ensures that the keyvals always gets indented.

To illustrate what I mean, I've created this program:

package main

import (
	"os"

	"github.com/charmbracelet/log"
)

const (
	userId  = "31c572eb-abb8-4907-b4ad-9c66799c4895"
	orderId = "6b3508f9-cfbe-41d7-8c4d-d4c399bee604"
)

func main() {
	logger := log.New(os.Stdout)
	logger.Info("Successfully placed order.",
		"user_id", userId,
		"order_id", orderId,
	)
}

Running itprints the message as a single line like this:

Screenshot 2024-04-16 at 20 45 25

However, I looked a bit at the code, and saw that there was an indentation separator. Is there a way to ensure that it gets applied to all keyvals without having to add newlines to each value like this:

logger.Info("Successfully placed order.",
	"user_id", userId+"\n",
	"order_id", orderId+"\n",
)
Screenshot 2024-04-16 at 20 49 01
@maaslalani
Copy link
Contributor

Perhaps we can add an option that allows you to do something like?

log.New().Multiline(true)

On the other hand @creativecreature, is there a particular reason you want to avoid adding new lines if that gives you the desired result?

@viccon
Copy link
Author

viccon commented Apr 27, 2024

I think that your proposed option would be great! I'm currently using a similar approach, though it does become a little tedious over time. The new lines does not really give me the result I'm after, but it's better than having a really long line! With a Multiline option I think both the aesthetics and readability would be improved if the key and value would be aligned on the same line

@decentral1se
Copy link

decentral1se commented Jul 7, 2024

Yessssss 🎉 Just chiming in here to say that this would be a huuuuuge usability win. Especially for programs which have large traces with keyvals which end-users have to read through. I've just migrated a large project to use this package, was pretty painless!

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

3 participants