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

journal: SendVals with arbitrary auto-converting functions #454

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lzap
Copy link

@lzap lzap commented Jan 6, 2025

Hello,

I am working on log/slog handler implementation for our project using this library and the API does only allow passing journald fields as a map of strings. The log/slog implementation is designed around slices of attributes (with some array-based optimalization hacks to decrease allocation count), I would like to follow the suit and avoid conversion to maps.

This patch adds new function SendVals and Value interface which allows the API users to use alternative syntax to provide journald values:

journal.SendVals(message, journal.PriInfo,
	journal.String("KEY", "VALUE"),
	journal.Int("INT_KEY", 1),
)

The whole suite of helper fucntions is provided, but they immediately convert the value to string since carrying the type does not make much sense in this case as the value is immediately written to byte buffer and sent to journald. It is just a syntactic sugar I thought might be useful, for my usecase only the journal.String is enough.

Keeping all those options is useful because all are named in a same fasion as in the official log/slog logging library so people might be familiar with it this way.

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

Successfully merging this pull request may close these issues.

1 participant