#include <iostream>
#include <set>
#include <algorithm>

template<typename CharT = char,
         typename CharTraits = std::char_traits<CharT> >
class Logger : public std::basic_ostream<CharT, CharTraits>,
               private std::basic_streambuf<CharT, CharTraits>
{
    typedef std::basic_streambuf<CharT, CharTraits> streambuf_type;
    typedef std::basic_ostream<CharT, CharTraits> ostream_type;

    std::set<streambuf_type*> mStreambufs;

public:

    typedef CharT char_type;
    typedef CharTraits traits_type;

    typedef typename std::set<streambuf_type*>::iterator iterator;
    typedef typename std::set<streambuf_type*>::const_iterator const_iterator;

    Logger():
        ostream_type{this} {}

    iterator begin() { return mStreambufs.begin(); }
    iterator end() { return mStreambufs.end(); }
    const_iterator begin() const { return mStreambufs.cbegin(); }
    const_iterator end() const { return mStreambufs.cend(); }

    std::pair<iterator, bool> add( streambuf_type* ptr ) { return mStreambufs.insert(ptr); }
    std::pair<iterator, bool> add( ostream_type& ptr ) { return add(ptr.rdbuf()); }

    void erase( iterator i ) {  mStreambufs.erase(i); }

protected:

    virtual typename traits_type::int_type overflow( typename traits_type::int_type c = traits_type::eof() ) override
    {
        typename traits_type::int_type rval = traits_type::not_eof(c);

        if( !traits_type::eq_int_type( rval, c ) ) /// EOF - no characters to be written. Return success.
            return rval;

        for( auto ptr : *this )
            if( traits_type::eq_int_type( ptr->sputc( traits_type::to_char_type(c) ), traits_type::eof() ) )
                rval = traits_type::eof(); // if one streambuf returns a value indicating failure, all other streambufs are done and EOF is returned.

        return rval;
    }
};

#include <fstream>

int main()
{
    Logger<> logger;
    logger.add( std::cout );

    logger << "Hallo Welt!\nWie gehts?" << std::endl;
}