Returning reference to stack-created value is undefined behavior:
Poco::LogStream& MyLogger::operator()()
{
//...
LogStream lstr(logger);
return lstr;
}
LogStream must outlive the execution of operator(); try something along these lines:
class MyLogger
{
public:
MyLogger(): lstr(0) /* ... */ { }
~MyLogger() { delete lstr; }
// ...
Poco::LogStream& operator()()
{
// ...
if (!lstr) lstr = new LogStream(logger)
return *lstr;
}
private:
LogStream* lstr;
};
If operator() is called from multiple threads, you should shield the LogStream creation time with a Mutex.