rs / zerolog

Zero Allocation JSON Logger
MIT License
10.33k stars 564 forks source link

Is there a way to obtain the 'buf' from the Event in a hook? #637

Open WUST-mengqinyu opened 7 months ago

WUST-mengqinyu commented 7 months ago

Or alternatively, is it possible to get the 'Context' in the Writer?

RmStorm commented 5 months ago

I would like something like this too! I have a hook that adds trace data to the logs. In that (or another) hook I would also like to add bits and pieces of the log event to the trace in cases of high severity. However now it's not possible to lift any information out of the zerolog event. a .Read() method on the event would be very nice.

edit: On further reading there seems to be a workable solution here https://github.com/rs/zerolog/issues/493 @WUST-mengqinyu would be nicer with something that doesn't involve reflecting though.

rs commented 5 months ago

The buf is an internal structure containing the incomplete event in the making. It is not meant to be exposed.