Skip to content

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

@mgorshkov

Description

@mgorshkov

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions