Protologs has sample Go code that demonstrates structured and strongly typed logging using Uber Zap and Protobuf.
This works by using a zap_marshaler protoc plugin that generates code from Proto messages that implements Zap's ObjectMarshaler
interface. Proto generated structs can then be logged with zap.Object(&someProtoStruct{})
Proto definitions for logs in /proto have base log context fields and service-specific field examples. These files are compiled to the /pkg/protolog directory with protoc
.
protoc --zap-marshaler_out=./pkg/protolog --go_out=./pkg/protolog proto/protolog/*.proto
usersvc/main.go
and paymentsvc/main.go
are examples that both use a common base proto message, but different service-level proto messages.
Run with go run paymentsvc/main.go
etc.