title: Threadsafe logging
body: <p>I want to implement a simple class for logging from multiple threads. The idea there is, that each object that wants to log stuff, receives an ostream-object that it can write messages to using the usual operators. The desired behaviour is, that the messages are added to the log when the stream is flushed. This way, messages will not get interrupted by messages from other threads. I want to avoid using a temporary stringstream to store the message, as that would make most messages at least twoliners. As I see it, the standard way of achieving this would be to implement my own streambuffer, but this seems very cumbersome and error-prone. Is there a simpler way to do this? If not, do you know a good article/howto/guide on custom streambufs?</p>
  
  <p>Thanks in advance,</p>
  
  <p>Space_C0wbo0y</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Since it seems to work I added my own answer.</p>