an-tao / trantor

a non-blocking I/O tcp network lib based on c++14/17
Other
387 stars 131 forks source link

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

Open mgorshkov opened 1 month ago

mgorshkov commented 1 month ago

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:

We can propose 2 solutions:

trantor

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

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 commented 1 month ago

@an-tao Please comment on this