Replies: 2 comments 2 replies
-
Since structures are incompatible if even one attribute is added, adding one attribute would be no different than allowing users to use their own |
Beta Was this translation helpful? Give feedback.
1 reply
-
How about using mdc ? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to check if this is acceptable before attempting a PR or if there is existing work. Could be related to structured logging, but I think what I need is simpler.
Proposal
It would be great if I could attach custom user data to
spdlog::details::log_msg
via a simplevoid*
pointer. From there I can add a regularspdlog::custom_flag_formatter
to use the pointer data however I need.In my case I want a way to add arbitrary prefixes at the start of the log line. spdlog supports custom log level names but I need more prefixes than
spdlog::level::n_levels
and I need the semantics separated from the logging levels.This could be optional behind
#ifdef SPDLOG_LOG_MSG_USERDATA
.Alternative
I've already implemented an alternative where I encode the info I need in the
log_msg::payload
and then decode it in a custom flag formatter. Two main downsides to this approach:const_cast
in the flag formatter to "trim" the encoded info out of the payload. Works now but could violate spdlog preconditions in the future.I'm not happy with this alternative as a production solution.
Beta Was this translation helpful? Give feedback.
All reactions