Comments (8)
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.
@rs it's probably not significantly different in that regard to RawJSON?
from zerolog.
Sure
from zerolog.
@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.
@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.
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.
@pltr This is not exactly what you are looking for - but comes really close - toravir@8916864
Lemme know what you think..
from zerolog.
@pltr do you want to attempt a PR?
from zerolog.
Related Issues (20)
- Understanding "Zero Allocation" HOT 1
- Is there a recommended way to do batching of log lines and write at once ? HOT 1
- Logs as bytes in Stderr HOT 6
- Deep Example
- Latest official tagged release not up to date in github? HOT 1
- Add an option to limit max log's size after escaping
- Give debug level logs a color again
- ConsoleWriter uses the `level` field key to be invalid or panic? HOT 1
- diode writer does not flush when program exits HOT 1
- Should journald keys be sanitized to strip/replace invalid characters? HOT 2
- Differentiating Error Level Log Output in Terminal and Hook HOT 1
- getting name of the function where a log being called HOT 5
- Use TimestampFunc for sampling HOT 1
- Yu
- level, message are built-in keywords? Field keywords level or message are invalid HOT 1
- Hook after writing
- Support for msgpack encoder
- The README does not document the default log level of the library
- how to get Event timestamp in hook Run() ?
- Question: Using Dict Inside an Array would not put back the byte buffer back into pool, is this the expectation?
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 zerolog.