Giter VIP home page Giter VIP logo

Comments (8)

c4milo avatar c4milo commented on August 18, 2024

+1 here, it should not be forced.

from logrus.

sirupsen avatar sirupsen commented on August 18, 2024

Aye, could be an option like ForceColors.

from logrus.

c4milo avatar c4milo commented on August 18, 2024

yeah, something like SortFields

from logrus.

sirupsen avatar sirupsen commented on August 18, 2024

I'll happily accept a patch

from logrus.

snorkypie avatar snorkypie commented on August 18, 2024

I looked in to this and in order to do this we probably need to add another WithFields*-method since logrus.Fields{} is of type map[string]interface{}, which by nature is "random".

I have been playing around with making WithField() either take a ...interface{} and thus be able to handle multiple key/value pairs (which we could keep sorted) or to just add a WithFieldList() not to make people confused with the name being singular.

Any input on what would feel most natural?

from logrus.

sirupsen avatar sirupsen commented on August 18, 2024

Fixed in 538395b

from logrus.

snorkypie avatar snorkypie commented on August 18, 2024

The solution isn't this easy since entry.Data is of type Fields (map) and maps are random by nature.

Code:
logrus.SetFormatter(&logrus.TextFormatter{DisableSorting: true})
logrus.WithFields(logrus.Fields{"one": 1, "two": 2, "three": 3, "four": 4}).Info("one")
logrus.WithFields(logrus.Fields{"two": 2, "one": 1, "four": 4, "three": 3}).Info("two")
logrus.WithFields(logrus.Fields{"three": 3, "four": 4, "two": 2, "one": 1}).Info("three")

Output of run 1:
INFO[0000] one one=1 two=2 three=3 four=4
INFO[0000] two one=1 four=4 three=3 two=2
INFO[0000] three one=1 three=3 four=4 two=2

Output of run 2:
INFO[0000] one one=1 two=2 three=3 four=4
INFO[0000] two two=2 one=1 four=4 three=3
INFO[0000] three one=1 three=3 four=4 two=2

Notice how they now are random instead of sorted. We would have to change from the map type to a slice in order to implement this for real. Where they align correctly to their input is just pure luck.

from logrus.

sirupsen avatar sirupsen commented on August 18, 2024

Yes, that's what I expected, most aggregators are fine with that—I didn't do a full reimplementation with a slice. I'd happily accept a patch that does.

from logrus.

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.