X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fdebug%2Flogstream.hxx;h=4546a5e1d5cd6efbaa774eb475101a05584853af;hb=68eb7031e2dce999d112d0164fa28d4b8d66922e;hp=5b57d50f0f8f977cb162cd90ed2a72a364291b1f;hpb=70c6b48a07f78fdbaa2ca8839e48746ea3e884ee;p=simgear.git diff --git a/simgear/debug/logstream.hxx b/simgear/debug/logstream.hxx index 5b57d50f..4546a5e1 100644 --- a/simgear/debug/logstream.hxx +++ b/simgear/debug/logstream.hxx @@ -28,9 +28,8 @@ #include -// At least Irix needs this -#ifdef SG_HAVE_NATIVE_SGI_COMPILERS -#include +#ifdef _MSC_VER +# include #endif #ifdef SG_HAVE_STD_INCLUDES @@ -43,14 +42,11 @@ #include -#ifndef SG_HAVE_NATIVE_SGI_COMPILERS SG_USING_STD(streambuf); SG_USING_STD(ostream); +SG_USING_STD(cout); SG_USING_STD(cerr); SG_USING_STD(endl); -#else -SG_USING_STD(char_traits); -#endif #ifdef __MWERKS__ SG_USING_STD(iostream); @@ -69,7 +65,11 @@ SG_USING_STD(iostream); * messages at runtime. Only messages with priority >= logbuf::logPriority * and debugClass == logbuf::logClass are output. */ +#ifdef SG_NEED_STREAMBUF_HACK +class logbuf : public __streambuf +#else class logbuf : public streambuf +#endif { public: @@ -184,7 +184,23 @@ logbuf::set_log_state( sgDebugClass c, sgDebugPriority p ) inline logbuf::int_type logbuf::overflow( int c ) { +#ifdef _MSC_VER + static has_console = false; + if ( logging_enabled ) { + if ( !has_console ) { + AllocConsole(); + freopen("conin$", "r", stdin); + freopen("conout$", "w", stdout); + freopen("conout$", "w", stderr); + has_console = true; + } + sbuf->sputc(c); + } + else + return EOF == 0 ? 1: 0; +#else return logging_enabled ? sbuf->sputc(c) : (EOF == 0 ? 1: 0); +#endif } /** @@ -256,6 +272,7 @@ logstream::operator<< ( const loglevel& l ) return *this; } +extern logstream *global_logstream; /** * \relates logstream @@ -267,8 +284,22 @@ logstream::operator<< ( const loglevel& l ) inline logstream& sglog() { - static logstream logstrm( cerr ); - return logstrm; + if (global_logstream == NULL) { + +#ifdef __APPLE__ + /** + * There appears to be a bug in the C++ runtime in Mac OS X that + * will crash if certain funtions are called (in this case + * cerr.rdbuf()) during static initialization of a class. This + * print statement is hack to kick the library in the pants so it + * won't crash when cerr.rdbuf() is first called -DW + **/ + cout << "Using Mac OS X hack for initializing C++ stdio..." << endl; +#endif + global_logstream = new logstream (cerr); + } + + return *global_logstream; }