I wrote this logger. It works fine, but there is something I have not been able to do.
uLOG(warning) << "Test log message " << 123 << uLOGE;
uLOG locks a C++11 mutex and starts writing on a file stream.
uLOGE flushes the stream and unlocks the mutex.
I would like to get the same result with this syntax:
uLOG(warning) << "Test log message " << 123;
so I would like the flush and the unlock to be called automatically at the end of the line.
Which is a possible way to do it?
- I tried setting the
ios::unitbuf
flag, but this forces a flush for every<<
operator, not ideal for an SSD wearing. And it does not unlock the mutex. - I tried defining a temporary object in uLOG whose destructor would flush and unlock, but that forces to put the log line in its own code block:
{ uLOG(warning) << 123; }