SPDLOG_LOGGER_CALL with additional data and custom formatting #3012
-
Hi! So, I have a logger that I want to produce output in JSON format. If I call But I would like to introduce some additional data, beyond just the message string. For example, I may have something like this: enum Class Day {
Monday,
Tuesday,
Wednesday,
...
}
struct MessageContext {
Day day;
int count;
} Is there some way for me to include a MessageContext context{Day::Monday, 5};
SPDLOG_LOGGER_CALL(myLogger, myLogLevel, "Some message", context); And then have my logger produce final output like: {payload: "Some message", day: "Monday", count: 5} I believe this |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Additional log arguments are formatted by the fmt library, so a custom data formatter for fmt must be defined. However, spdlog does not have an API to output log data as JSON format. |
Beta Was this translation helpful? Give feedback.
-
Does this mean that my message would need to include a I suppose fmt does not do anything with additional arguments otherwise. |
Beta Was this translation helpful? Give feedback.
Additional log arguments are formatted by the fmt library, so a custom data formatter for fmt must be defined.
See: https://fmt.dev/9.1.0/api.html#formatting-user-defined-types
However, spdlog does not have an API to output log data as JSON format.
This should be customized by the developer.
See: #1797