#how to append prefix to variadic string argument?
8 messages · Page 1 of 1 (latest)
make a function that does so and you call instead of direct?
Probably use slog and optionally pack additional info into the context. There are a lot of ctxlog packages out there that you could use or examine
If it's just in one package, a utility function would work, but if it's to fully replace your logging solution, you might prefer something more versatile.
You could create a wrapper for your logger like;
func logWithLevel(level, msg string, args ...any) {
log.Printf(fmt.Sprintf("[%s] %s\n", strings.ToUpper(level), msg), args...)
}
UPDATE: If that is what you want to do that is. Agree with others here though - log/slog or any other structured logging lib is a better solution.
Are you sure that you don't want a log level by the name of TRACE or something?