// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the
-// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-// Boston, MA 02111-1307, USA.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
#include <simgear/compiler.h>
-// At least Irix needs this
-#ifdef SG_HAVE_NATIVE_SGI_COMPILERS
-#include <char_traits.h>
+#ifdef _MSC_VER
+# include <windows.h>
#endif
#ifdef SG_HAVE_STD_INCLUDES
#include <simgear/debug/debug_types.h>
-#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);
* 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:
*/
static void set_log_level( sgDebugClass c, sgDebugPriority p );
+
+ /**
+ * Set the allowed logging classes.
+ * @param c All enabled logging classes anded together.
+ */
+ static void set_log_classes (sgDebugClass c);
+
+
+ /**
+ * Get the logging classes currently enabled.
+ * @return All enabled debug logging anded together.
+ */
+ static sgDebugClass get_log_classes ();
+
+
+ /**
+ * Set the logging priority.
+ * @param c The priority cutoff for logging messages.
+ */
+ static void set_log_priority (sgDebugPriority p);
+
+
+ /**
+ * Get the current logging priority.
+ * @return The priority cutoff for logging messages.
+ */
+ static sgDebugPriority get_log_priority ();
+
+
/**
* Set the stream buffer
* @param sb stream buffer
*/
void set_sb( streambuf* sb );
+#ifdef _MSC_VER
+ static void has_no_console() { has_console = false; }
+#endif
+
protected:
/** sync/flush */
static streambuf* sbuf;
static bool logging_enabled;
+#ifdef _MSC_VER
+ static bool has_console;
+#endif
static sgDebugClass logClass;
static sgDebugPriority logPriority;
inline logbuf::int_type
logbuf::overflow( int c )
{
+#ifdef _MSC_VER
+ if ( logging_enabled ) {
+ if ( !has_console ) {
+ AllocConsole();
+ freopen("conin$", "r", stdin);
+ freopen("conout$", "w", stdout);
+ freopen("conout$", "w", stderr);
+ has_console = true;
+ }
+ return sbuf->sputc(c);
+ }
+ else
+ return EOF == 0 ? 1: 0;
+#else
return logging_enabled ? sbuf->sputc(c) : (EOF == 0 ? 1: 0);
+#endif
}
/**
return *this;
}
+extern logstream *global_logstream;
/**
* \relates logstream
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;
}