Convert unique_ptr based singleton to function-local static object

This commit is contained in:
Amish Naidu 2018-09-28 19:51:38 +05:30
parent 332199720d
commit 2436034af8
2 changed files with 3 additions and 7 deletions

View file

@ -45,7 +45,6 @@ namespace sn
Level m_logLevel;
std::ostream* m_logStream;
std::ostream* m_cpuTrace;
static std::unique_ptr<Log> m_instance;
};
//Courtesy of http://wordaligned.org/articles/cpp-streambufs#toctee-streams

View file

@ -2,17 +2,14 @@
namespace sn
{
std::unique_ptr<Log> Log::m_instance = nullptr;
Log::~Log()
{
}
Log& Log::get()
{
if (!m_instance)
m_instance.reset(new Log);
return *m_instance;
static Log instance;
return instance;
}
std::ostream& Log::getCpuTraceStream()
@ -77,4 +74,4 @@ namespace sn
m_tbuf(o1.rdbuf(), o2.rdbuf())
{}
}
}