[go: nahoru, domu]

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

trantor::LogStream <- std::ostream inheritance #345

Open
mgorshkov opened this issue Jul 23, 2024 · 1 comment
Open

trantor::LogStream <- std::ostream inheritance #345

mgorshkov opened this issue Jul 23, 2024 · 1 comment

Comments

@mgorshkov
Copy link

Hello!
It would be nice if trantor::LogStream class inherited std::ostream interface.
Currently, in our project we have to implement 2 stream redirections, or use templatized implementation, for every model class, to cover both cases:

  • Redirection to trantor::LogStream
  • Redirection to std::ostream.
    We are using LogStream for logging with trantor, and std::ostream to be compatible with standard C++ library, ex, to be able to use std::stringstream.
    If trantor::LogStream inherited std::ostream interface, the users could implement only one redirection function per each model class.

We can propose 2 solutions:

  • Create new proxy classes, which would implement std::streambuf/std::ostream interfaces correspondingly and seamlessly redirect all the calls into trantor::LogStream or trantor::LogStream::Buffer (via 'append' method) like this (this is just an example):

trantor

This will require another logger, and a new implementation of LOG_INFO, LOG_DEBUG etc macros, since this utilises another stream implementation.

  • Inherit trantor::LogStream from std::ostream and implement forwarding into trantor's LogStream::Buffer in there (old interfaces are left where they are, but this option will require additional effort to maintain backward capability).

Actually, we have already implemented option 1 in our codebase, and it proved to work fine, but the drawback is that now we have to maintain 2 loggers - the old trantor's native logger, and the new std::ostream-compatible logger. If it was possible to implement either of options 1 or 2 in the trantor library directly, it would be nice.
What does the community think about this idea?

@mgorshkov
Copy link
Author

@an-tao Please comment on this

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

1 participant