Separated logging code into different .cpp/.h files.

This commit is contained in:
Daviw Williams
2014-01-24 15:21:59 +01:00
parent 8d5f6af7cd
commit c177891e5d
5 changed files with 270 additions and 206 deletions

View File

@ -25,93 +25,6 @@ freely, subject to the following restrictions:
namespace PolyVox
{
/**
* \return A pointer to the null stream.
*/
std::ostream* getNullStream(void)
{
// Passing zero to the stream constructor guarentees it will discard all input. See
// here http://stackoverflow.com/a/8244052 and here http://stackoverflow.com/a/6240980
static std::ostream s_NullStream(0);
return &s_NullStream;
}
// These create the global stream instances, created on demand.
namespace Impl
{
std::ostream*& getTraceStreamInstance()
{
static std::ostream* s_pTraceStream = getNullStream();
return s_pTraceStream;
}
std::ostream*& getDebugStreamInstance()
{
static std::ostream* s_pDebugStream = getNullStream();
return s_pDebugStream;
}
std::ostream*& getInfoStreamInstance()
{
static std::ostream* s_pInfoStream = &(std::cout);
return s_pInfoStream;
}
std::ostream*& getWarningStreamInstance()
{
static std::ostream* s_pWarningStream = &(std::cerr);
return s_pWarningStream;
}
std::ostream*& getErrorStreamInstance()
{
static std::ostream* s_pErrorStream = &(std::cerr);
return s_pErrorStream;
}
std::ostream*& getFatalStreamInstance()
{
static std::ostream* s_pFatalStream = &(std::cerr);
return s_pFatalStream;
}
}
void setTraceStream(std::ostream* pStream)
{
Impl::getTraceStreamInstance() = pStream;
}
void setDebugStream(std::ostream* pStream)
{
Impl::getDebugStreamInstance() = pStream;
}
void setInfoStream(std::ostream* pStream)
{
Impl::getInfoStreamInstance() = pStream;
}
void setWarningStream(std::ostream* pStream)
{
Impl::getWarningStreamInstance() = pStream;
}
void setErrorStream(std::ostream* pStream)
{
Impl::getErrorStreamInstance() = pStream;
}
// Fatal stream for logging
std::ostream*& getFatalStreamInstance()
{
static std::ostream* s_pFatalStream = &(std::cerr);
return s_pFatalStream;
}
void setFatalStream(std::ostream* pStream)
{
getFatalStreamInstance() = pStream;
}
#ifndef POLYVOX_THROW_ENABLED
void defaultThrowHandler(std::exception& e, const char* file, int line)