I have the following logging structure:
[STDERR] 2018-07-09 11:06:16.003 INFO some_pkg/main.go:232 Logging message 1 {"pid": 8842, "process": "some_process"}
[STDERR] 2018-07-09 11:06:16.006 DEBUG some_pkg/main.go:291 Logging message 2 {"pid": 8842, "process": "other_process"}
[STDERR] 2018-07-09 11:06:16.009 INFO some_pkg/main.go:345 Logging message 3 {"pid": 8842, "process": "some_process"}
You can see there are five types of information in this logging snippet. There are date/time, log-level, occurrence, message and a JSON fields (except [STDERR] field). Which means I have five columns in my logging structure. I would like to add a new columns with key pid and process (from the JSON). How should I do this with ZAP encoders and configs? I didn't find a solution for that in the ZAP documentation.
I use the following code to add fields to the logging:
logger = logger.With(zap.Field{Key: "pid", Type: zapcore.Int64Type, Integer: int64(os.Getpid())})
But the pid field's value goes to a JSON (what you can see above) and I would like to see it in a new column. There is an easy way in ZAP to do this?
My desired structure would be the following with the previous example:
[STDERR] 2018-07-09 11:06:16.003 INFO some_pkg/main.go:232 Logging message 1 8842 some_process
[STDERR] 2018-07-09 11:06:16.006 DEBUG some_pkg/main.go:291 Logging message 2 8836 other_process
[STDERR] 2018-07-09 11:06:16.009 INFO some_pkg/main.go:345 Logging message 3 8842 some_process