Code Monkey home page Code Monkey logo

Comments (10)

bersace avatar bersace commented on August 21, 2024

I can submit a patch, of course.

from tint.

lmittmann avatar lmittmann commented on August 21, 2024

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.

bersace avatar bersace commented on August 21, 2024

Hi @lmittmann thanks for the review. I'll submit a patch to give more control on output.

from tint.

bersace avatar bersace commented on August 21, 2024

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.

lmittmann avatar lmittmann commented on August 21, 2024

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.

bersace avatar bersace commented on August 21, 2024

@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.

lmittmann avatar lmittmann commented on August 21, 2024

Yes. Default formatting as is and any customization via ReplaceAttr.

from tint.

bersace avatar bersace commented on August 21, 2024

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.

lmittmann avatar lmittmann commented on August 21, 2024

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 and level check if type is time.Time/slog.Level:
    • if type is Time/Level apply tint's default formatting
    • if not append the attr's value
  • 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.

bersace avatar bersace commented on August 21, 2024

ok, got it.

from tint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.