logstream improvements from Yon Uriarte

Avoid descending into iostream when a message won't be logged.
This commit is contained in:
timoore
2008-11-29 00:17:29 +00:00
parent fa7490fb38
commit ae5297e6d7
2 changed files with 35 additions and 8 deletions
+15 -2
View File
@@ -34,6 +34,17 @@ sgDebugClass logbuf::logClass = SG_NONE;
sgDebugPriority logbuf::logPriority = SG_INFO;
streambuf* logbuf::sbuf = NULL;
namespace {
struct ignore_me
{
ignore_me()
{
logstream::initGlobalLogstream();
}
};
static ignore_me im;
}
logbuf::logbuf()
{
// if ( sbuf == NULL )
@@ -92,10 +103,12 @@ logstream::setLogLevels( sgDebugClass c, sgDebugPriority p )
logbuf::set_log_level( c, p );
}
void
logstream *
logstream::initGlobalLogstream()
{
// Force initialization of cerr.
static std::ios_base::Init initializer;
global_logstream = new logstream(std::cerr);
if( !global_logstream )
global_logstream = new logstream(std::cerr);
return global_logstream;
}