Review color and wording
bersace opened this issue · 10 comments
Hi,
This is a matter of taste, but please allow me to open a discussion on the color and formatting of tint.
Here is the output on WezTerm using Twilight (base16) color scheme:
Here are some notes:
- message and attributes values look dimmed.
- It's hard to distinguish debug line from info lines.
I suggest to use journalctl output as a reference:
- apply level color to message
- use journalctl level colors
- Use
DEBUG
,INFO
,WARN
andERROR
level string (note the padding space to always fit in 5 chars). - brigthen values
Here is a sample output (just from a simple dumb script) :
What do you think of this ?
Thanks for tint, it's a great module.
Regards,
I can submit a patch, of course.
message and attributes values look dimmed.
It's hard to distinguish debug line from info lines.
Something seems wrong with the colors in your terminal. tint
uses standard ANSI colors (https://en.wikipedia.org/wiki/ANSI_escape_code#Colors), nothing fancy. Do other go packages that provide coloring work in your terminal?
apply level color to message
use journalctl level colors
Use DEBUG, INFO , WARN and ERROR level string (note the padding space to always fit in 5 chars).
brigthen values
The style of the logs displayed by this package is opinionated. It resemble the zerolog.ConsoleWriter. I am open to ideas on how to make certain aspects of the style configurable. You are also welcome to fork the code and change the style to your needs.
Hi @lmittmann thanks for the review. I'll submit a patch to give more control on output.
You're right, I changed my terminal color scheme for more distinctive dim/normal/bright fonts. #11 is enough to achieve my goal of journalctl like output. One can even remove the level name and only use colored message to distinguish level.
As a side effect, #11 allows tint to support custom level as documented here : https://pkg.go.dev/golang.org/x/exp@v0.0.0-20230321023759-10a507213a29/slog#Level
Thank's for the PR #11. Your solutions works great for customizing levels, but there might be other needs for customization. E.g. hiding time (#9). I like @telemachus suggestion to addapted slog's ReplaceAttr
logic. It provides a more general solution that whould allow to not only solve your level issue, but also hide the timestamp or colorize e.g. the message.
@lmittmann . Sorry, I missed the comment. I'm hard to tracking a topic in issue and PR >_<
If I understand properly, you want to delegate formatting to a ReplaceAttr callback with default implementation to format as zerolog.ConsoleWriter ?
Yes. Default formatting as is and any customization via ReplaceAttr
.
Ok, but then, ReplaceAttr should return a string, right ? How would handler knows what to write ?
Something like that ?
a := h.replaceAttr(slog.Attr(slog.TimeKey, slog.TimeValue(r.Time)))
if a.key != "" {
buf.WriteString(a.Value.String())
}
a := h.replaceAttr(slog.Attr(slog.LevelKey, slog.IntValue(r.Level)))
if a.key != "" {
buf.WriteByte(' ')
buf.WriteString(a.Value.String())
}
a := h.replaceAttr(slog.Attr(slog.MessageKey, slog.StringValue(r.Message)))
if a.key != "" {
buf.WriteByte(' ')
buf.WriteString(a.Value.String())
}
...
The API and behavior of ReplaceAttr should be equal to slog
's API.
ReplaceAttr func(groups []string, a Attr) Attr
I' am not 100% sure about the edgecase, but essentially it could look something like this:
- if key is
""
don't write attr - for
time
andlevel
check if type istime.Time
/slog.Level
:- if type is
Time
/Level
apply tint's default formatting - if not append the attr's value
- if type is
- for everything else write the replaced attr
So if you want to customize e.g. the Level color you could replace the Level value with a string value containing custom ANSI codes.
ok, got it.