rs / zerolog

Zero Allocation JSON Logger
MIT License
10.41k stars 567 forks source link

Add Prehook and Pretimestamp features: this allows "time" key come first #458

Closed ikedam closed 1 year ago

ikedam commented 2 years ago

Multiple log files can be sorted with sort if "time" key comes first. For example:

$ cat node1.log nod2.log node3.log | sort
{"time":"2022-08-06T08:02:01Z","level":"info","node":"node1","message":"foo"}
{"time":"2022-08-06T08:02:12Z","level":"info","node":"node2","message":"bar"}
{"time":"2022-08-06T08:03:03Z","level":"info","node":"node1","message":"bar"}
{"time":"2022-08-06T08:03:10Z","level":"info","node":"node3","message":"bar"}
...

It would be useful in environments where logs aren't managed with log managing systems like Google Cloud Logging, AWS CloudWatch, and so on.

What I did:

tfogo commented 1 year ago

+1 for this feature. I was just about to ask about adding prehooks and found this PR. Prehooks like this will be useful for making logs more easily human readable.

@rs is there any interest in adding this feature? (Thanks for your work on zerlolog btw, it's great!)

tfogo commented 1 year ago

Hi @rs, sorry to bother you again. I just wanted to check in to see if this is something you would consider adding? If there's anything I could do to help get this merged, please let me know.

Thanks again for all your work on zerolog.

rs commented 1 year ago

I'm not comfortable adding such complexity just for field ordering. I would recommend using tools to read JSON logs instead of dealing with raw output.

ikedam commented 1 year ago

Thanks for comments. Close with won't merge.