Git Product home page Git Product logo

Comments (5)

inconshreveable avatar inconshreveable commented on June 12, 2024 1

Yeah, we need a way to make the formatter more customizable. I like the idea of setting up functional options for the LogFmtFormat constructor and letting you pass those in. So the API might look like:

func LogFmtFormat(opts ...FormatOption)

And usage:

// default
fmtr  := log.LogFmtFormat()

// customized formatter
fmtr := log.LogFmtFormat(
    log.WithTimeFormat(func(time.Time) string {
        return "Hammer Time!"
    }),
    log.WithMessagePadding(10),
    log.WithTimelKey("time"),
    log.WithLevelKey(""), // empty string means omit
)

This would address #84 and some other issues we closed in the past.Maybe we could even share some of the options with the JSONFormatter. Thoughts?

@ChrisHines thoughts on this API? I think it would get us some flexibility in custom formatting we were always missing. I wonder if this is a better way to allow folks to define custom names for t, lvl, and msg keys instead of the RecordKeyNames that we eventually settled on

from log15.

ChrisHines avatar ChrisHines commented on June 12, 2024

@grahamking started down the path of functional options in #60 but abandoned it for a custom formatter the better fit his needs.

The log.WithTimeFormat approach is interesting because it doesn't assume you are using time.Format.

from log15.

inconshreveable avatar inconshreveable commented on June 12, 2024

interesting. @kevinburke or I might take a stab at resurrecting that approach. do you like the way that worked out for StdlibAdapterOption in go-kit/log?

from log15.

ChrisHines avatar ChrisHines commented on June 12, 2024

I don't use StdlibAdapter much and I didn't write it either, credit for that idea goes to @peterbourgon, but I do like how functional options work for this sort of thing.

from log15.

kishaningithub avatar kishaningithub commented on June 12, 2024

Instead of functional style options like above why not pass in an options struct?

In the struct the user can specify only the options they need and rest all is default. I have seen this approach in the Kafka go library

Examples

https://pkg.go.dev/github.com/segmentio/kafka-go?utm_source=godoc#Writer

https://github.com/segmentio/kafka-go/blob/v0.4.32/reader.go#L622

from log15.

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.