Comments (10)
I can submit a patch, of course.
from tint.
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.
from tint.
Hi @lmittmann thanks for the review. I'll submit a patch to give more control on output.
from tint.
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/[email protected]/slog#Level
from tint.
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.
from tint.
@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 ?
from tint.
Yes. Default formatting as is and any customization via ReplaceAttr
.
from tint.
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())
}
...
from tint.
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.
from tint.
ok, got it.
from tint.
Related Issues (20)
- TimeFormat does not appear to take effect HOT 1
- Allow user to set custom time format HOT 1
- More log levels please HOT 3
- Adding a replace attribute function broke feature HOT 3
- Can I set custom level tags? HOT 2
- ReplaceAttrs incompatible with slog HOT 1
- feat request: colorize the message HOT 2
- bug: nested group name was wrong in `Err` attribute HOT 2
- Sorting attrs? HOT 3
- isatty no longer necessary HOT 1
- Is it possible to add a custom time location? HOT 1
- Still colorize level when replaceAttr exist HOT 5
- Fields names are not printed for C structures HOT 4
- Wrong colors somehow HOT 1
- Log files HOT 2
- Colorized attribute HOT 2
- Test TestReplaceAttr fails sometimes HOT 1
- Custom log level names with color HOT 3
- TimeFormat can lead to misaligned output HOT 2
- Log level change HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tint.