Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom formatting of user defined types #140

Open
rajnishdahiya opened this issue Mar 14, 2022 · 2 comments
Open

Custom formatting of user defined types #140

rajnishdahiya opened this issue Mar 14, 2022 · 2 comments

Comments

@rajnishdahiya
Copy link

BINLOG_ADAPT_STRUCT allows logging used defined types and their members. However, the user has no control over the formatting when the type is pretty-printed.

One possibility is to simply do the formatting on the producer side, but that is less than ideal for performance.

What's the best way to add support for custom formatting of user defined types, preferably via a standard interface like operator<<?

@erenon
Copy link
Contributor

erenon commented Mar 16, 2022

To pretty print custom structures, there are two options:

@rajnishdahiya
Copy link
Author

Your suggestion seems to pretty-fy adapted structs.
I am looking to avoid adapting all together as it can get quite messy for my logging needs, e.g. my type might have a vector and I want to log only 1st few entries of it. Also in my project it's advised to have a standard logging mechanism (implementing operator << or fmt::format), I was hoping to use same infrastructure.

I didn't look deeper but will something like below work?
Have a dedicated thread for consuming from queues. And writing out directly to text format, i.e. TextOutputStream.

  1. Pass (log) a pointer as binlog::address or void*, along with some tag/category (saying it's a user_defined_type Type1)
  2. Customize serialization (mserialize, ToStringVisitor etc)
  3. check for special tag/category, if yes then extract pointer from buffer, cast it to Type1 and use already defined fmt::format, operator << etc for that type to serialize.
    I am aware of potential issues of using dangling pointers and logging outdated object state here, but let's assume that is acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants