Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards


Class template basic_text_ostream_backend

boost::log::sinks::basic_text_ostream_backend — An implementation of a text output stream logging sink backend.


// In header: <boost/log/sinks/text_ostream_backend.hpp>

template<typename CharT> 
class basic_text_ostream_backend : public basic_formatted_sink_backend< CharT, combine_requirements< synchronized_feeding, flushing >::type >
  // types
  typedef base_type::char_type            char_type;    // Character type. 
  typedef base_type::string_type          string_type;  // String type to be used as a message text holder. 
  typedef std::basic_ostream< char_type > stream_type;  // Output stream type. 

  // construct/copy/destruct
  template<typename... ArgsT> 
    explicit basic_text_ostream_backend(ArgsT... const &);

  // public member functions
  void add_stream(shared_ptr< stream_type > const &);
  void remove_stream(shared_ptr< stream_type > const &);
  void auto_flush(bool = true);
  void set_auto_newline_mode(auto_newline_mode);
  void consume(record_view const &, string_type const &);
  void flush();


The sink backend puts formatted log records to one or more text streams.

basic_text_ostream_backend public construct/copy/destruct

  1. basic_text_ostream_backend();

    Constructor. No streams attached to the constructed backend, auto flush feature disabled.

  2. template<typename... ArgsT> 
      explicit basic_text_ostream_backend(ArgsT... const & args);

    Constructor. Creates a sink backend with the specified named parameters. The following named parameters are supported:

    • auto_flush - Specifies a flag, whether or not to automatically flush the attached streams after each written log record. By default, is false.

    • auto_newline_mode - Specifies automatic trailing newline insertion mode. Must be a value of the auto_newline_mode enum. By default, is auto_newline_mode::insert_if_missing.

  3. ~basic_text_ostream_backend();


basic_text_ostream_backend public member functions

  1. void add_stream(shared_ptr< stream_type > const & strm);

    The method adds a new stream to the sink.



    Pointer to the stream. Must not be NULL.

  2. void remove_stream(shared_ptr< stream_type > const & strm);

    The method removes a stream from the sink. If the stream is not attached to the sink, the method has no effect.



    Pointer to the stream. Must not be NULL.

  3. void auto_flush(bool enable = true);

    Sets the flag to automatically flush buffers of all attached streams after each log record.



    The flag indicates whether the automatic buffer flush should be performed.

  4. void set_auto_newline_mode(auto_newline_mode mode);

    Selects whether a trailing newline should be automatically inserted after every log record. See auto_newline_mode description for the possible modes of operation.



    The trailing newline insertion mode.

  5. void consume(record_view const & rec, string_type const & formatted_message);

    The method writes the message to the sink.

  6. void flush();

    The method flushes all attached streams.