#1076·zap

ConsoleEncoder: add option to format the context as key=value pairs

Author: dnephinCreated Mar 31, 2022Updated Sep 20, 2025
Labelsenhancement

This is my first time using zap. I've used a couple other logging libraries in Go (logrus, go-hclog). In both of those libraries the "human readable" format would format the context as key=value pairs. I was a bit surprised to see that zap encodes the whole context as JSON.

What I'd like is to use the ConsoleEncoder when the application is run with a terminal (dev and test), and switch to the JSONEncoder when the application is run in production. That mostly works, but a lot of the important details in the log are part of the context, and formatting the context as JSON makes it not super readable.

Do you think it would be reasonable to add an option to the ConsoleEncoder to allow formatting the context as key=value pairs instead of JSON? Would you accept a PR that adds that support?

Thank you!