Giter Site home page Giter Site logo

Comments (8)

rs avatar rs commented on July 28, 2024

You have to be aware that this feature would not be portable to the binary serialization (cc @toravir). Other than that, I'm fine with the idea.

from zerolog.

pltr avatar pltr commented on July 28, 2024

@rs it's probably not significantly different in that regard to RawJSON?

from zerolog.

rs avatar rs commented on July 28, 2024

Sure

from zerolog.

toravir avatar toravir commented on July 28, 2024

@pltr - can't this be done using the LogObjectMarshaler() callback ?? imo, users should not be aware of the zerolog's internal buffer. RawJSON() api does not build the JSON piece by piece - so this is slightly different, but possible in cbor...

from zerolog.

pltr avatar pltr commented on July 28, 2024

@toravir I'm not sure I follow. Given that price object above and the following call:

log.Info().Str("foo", "bar").Object("price", &price).Msg("Price is too high")

Would it be possible, assuming Price implements LogObjectMarshaler to result in

{"l":"info", "foo": "bar", "price": "$64.49", "m":"Price is too high"}

?
It seems MarshalZerologObject receives zerolog.Event object as the argument and Event doesn't seem to contain any methods that would allow the user to directly print into the current value. And even if it did it would leak the details significantly more than a generic JSOM buffer interface.

JSONAppendable isn't actually aware of anything, it's not even zerolog specific, it just expects a byte buffer and returns a filled buffer and that's about it. The only expectation there really is that the data it fills the buffer with is supposed to be a valid JSON value. Which means it's very generic in nature and can be used with any similar json serializer, so it's composable - you can stack a few of them together and they will just work. Of course in the case of zerolog it also means it's going to be zero copy/zero allocation, but but it's an implementation detail, however important.

from zerolog.

toravir avatar toravir commented on July 28, 2024

Oh.. i know what you mean - the Object() api will make it look like ..,"price":{"value":"$64.49"},.. - it is not a clean log as "price":"$64.49"

Thinking about it... agree about JSONAppendable - it just adds its data as json value to the provided byte slice.

from zerolog.

toravir avatar toravir commented on July 28, 2024

@pltr This is not exactly what you are looking for - but comes really close - toravir@8916864
Lemme know what you think..

from zerolog.

rs avatar rs commented on July 28, 2024

@pltr do you want to attempt a PR?

from zerolog.

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.