Temporary object used for forming logger messages.
More...
#include <Logger.hh>
|
|
| Message (Message &&other)=default |
| |
| | Message (std::vector< std::ostream * > &vec, std::mutex *mtx) |
| |
| | operator bool () const |
| |
| template<typename OutputType> |
| Message & | operator<< (const OutputType &out) |
| |
| Message & | operator<< (std::ios_base &(*manip)(std::ios_base &)) |
| | Backup overload for extra output manipulators.
|
| |
| Message & | operator<< (std::ostream &(*manip)(std::ostream &)) |
| | Allows the Message to accept standard stream manipulators (like std::endl) via operator<<.
|
| |
|
Message & | operator= (Message &&other)=default |
| |
|
| std::ostringstream | buffer_ |
| |
| std::mutex * | mtx_ |
| |
| std::vector< std::ostream * > | osvec_ |
| | Active output streams that should receive the Message.
|
| |
Temporary object used for forming logger messages.
Upon destruction, a newline is appended to the message. This is based on a trick from https://stackoverflow.com/a/57553824
Definition at line 172 of file Logger.hh.
◆ Message()
| marley::Logger::Message::Message |
( |
std::vector< std::ostream * > & | vec, |
|
|
std::mutex * | mtx ) |
|
inline |
Definition at line 176 of file Logger.hh.
std::vector< std::ostream * > osvec_
Active output streams that should receive the Message.
◆ ~Message()
| marley::Logger::Message::~Message |
( |
| ) |
|
|
inline |
Definition at line 190 of file Logger.hh.
190 {
191
192
193 if (
osvec_.empty() )
return;
194
195
197 std::string msg =
buffer_.str();
198 std::lock_guard< std::mutex > lock( *
mtx_ );
199 for (
auto& s :
osvec_ ) *s << msg;
200 }
std::ostringstream buffer_
◆ operator bool()
| marley::Logger::Message::operator bool |
( |
| ) |
const |
|
inlineexplicit |
◆ operator<<() [1/3]
template<typename OutputType>
| Message & marley::Logger::Message::operator<< |
( |
const OutputType & | out | ) |
|
|
inline |
Definition at line 202 of file Logger.hh.
204 {
205
206
207
209 return *this;
210 }
◆ operator<<() [2/3]
Backup overload for extra output manipulators.
Definition at line 326 of file Logger.cc.
328{
330 return *this;
331}
References buffer_.
◆ operator<<() [3/3]
◆ buffer_
| std::ostringstream marley::Logger::Message::buffer_ |
|
protected |
Used to cache output from multiple calls to operator<< until we have the full message. Then we just emit it in a single-step for each active OutStream, all at once. This together with a std::mutex prevents splitting logging messages due to race conditions between parallel threads.
Definition at line 228 of file Logger.hh.
Referenced by operator<<(), and operator<<().
◆ mtx_
| std::mutex* marley::Logger::Message::mtx_ |
|
protected |
std::mutex to use to lock streaming output when emitting the final message
Definition at line 235 of file Logger.hh.
◆ osvec_
| std::vector< std::ostream* > marley::Logger::Message::osvec_ |
|
protected |
Active output streams that should receive the Message.
Definition at line 231 of file Logger.hh.
The documentation for this class was generated from the following files: