Commit 5c989b9d authored by Julien Michel's avatar Julien Michel

ENH: Refactor singleton pattern to be thread-safe and simpler

parent 7e1229c0
......@@ -61,7 +61,7 @@ private:
Logger(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
static Pointer Singleton;
static Pointer CreateInstance();
}; // class Logger
......
......@@ -29,25 +29,28 @@
namespace otb
{
Logger::Pointer Logger::Singleton = ITK_NULLPTR;
Logger::Pointer Logger::Instance()
Logger::Pointer Logger::CreateInstance()
{
if(!Logger::Singleton)
{
Logger::Singleton = Logger::New();
Logger::Pointer instance = Logger::New();
// By default, redirect logs to std::cout
itk::StdStreamLogOutput::Pointer defaultOutput = itk::StdStreamLogOutput::New();
defaultOutput->SetStream(std::cout);
// By default, redirect logs to std::cout
itk::StdStreamLogOutput::Pointer defaultOutput = itk::StdStreamLogOutput::New();
defaultOutput->SetStream(std::cout);
instance->AddLogOutput(defaultOutput);
// Log setup information
instance->LogSetupInformation();
Logger::Singleton->AddLogOutput(defaultOutput);
return instance;
}
// Log setup information
Logger::Singleton->LogSetupInformation();
}
return Logger::Singleton;
Logger::Pointer Logger::Instance()
{
// Static locales are initialized once in a thread-safe way
static Logger::Pointer instance = CreateInstance();
return instance;
}
Logger::Logger()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment