#include <simgear/compiler.h>
-#ifdef _MSC_VER
+#ifdef _WIN32
# include <windows.h>
#endif
-#ifdef SG_HAVE_STD_INCLUDES
-# include <streambuf>
-# include <ostream>
-#else
-# include <iostream.h>
-# include <simgear/sg_traits.hxx>
-#endif
+#include <streambuf>
+#include <ostream>
+#include <cstdio>
#include <simgear/debug/debug_types.h>
-SG_USING_STD(streambuf);
-SG_USING_STD(ostream);
-
-#ifdef __MWERKS__
-SG_USING_STD(iostream);
-#endif
+using std::streambuf;
+using std::ostream;
//
// TODO:
#endif
{
public:
-
-#ifndef SG_HAVE_STD_INCLUDES
- typedef char_traits<char> traits_type;
- typedef char_traits<char>::int_type int_type;
- // typedef char_traits<char>::pos_type pos_type;
- // typedef char_traits<char>::off_type off_type;
-#endif
// logbuf( streambuf* sb ) : sbuf(sb) {}
/** Constructor */
logbuf();
*/
void set_log_state( sgDebugClass c, sgDebugPriority p );
+ bool would_log( sgDebugClass c, sgDebugPriority p ) const;
+
/**
* Set the global logging level.
* @param c debug class
*/
void set_sb( std::streambuf* sb );
-#ifdef _MSC_VER
+#ifdef _WIN32
static void has_no_console() { has_console = false; }
#endif
static std::streambuf* sbuf;
static bool logging_enabled;
-#ifdef _MSC_VER
+#ifdef _WIN32
static bool has_console;
#endif
static sgDebugClass logClass;
inline int
logbuf::sync()
{
-#ifdef SG_HAVE_STD_INCLUDES
return sbuf->pubsync();
-#else
- return sbuf->sync();
-#endif
}
inline void
logging_enabled = ((c & logClass) != 0 && p >= logPriority);
}
+inline bool
+logbuf::would_log( sgDebugClass c, sgDebugPriority p ) const
+{
+ return ((c & logClass) != 0 && p >= logPriority);
+}
+
inline logbuf::int_type
logbuf::overflow( int c )
{
-#ifdef _MSC_VER
+#ifdef _WIN32
if ( logging_enabled ) {
if ( !has_console ) {
AllocConsole();
*/
void setLogLevels( sgDebugClass c, sgDebugPriority p );
+ bool would_log( sgDebugClass c, sgDebugPriority p ) const
+ {
+ return lbuf.would_log( c, p );
+ };
+
/**
* Output operator to capture the debug level and priority of a message.
* @param l log level
*/
inline std::ostream& operator<< ( const loglevel& l );
friend logstream& sglog();
+ static logstream *initGlobalLogstream();
protected:
static logstream *global_logstream;
- static void initGlobalLogstream();
};
inline std::ostream&
inline logstream&
sglog()
{
- if (logstream::global_logstream == NULL) {
- logstream::initGlobalLogstream();
- }
- return *logstream::global_logstream;
+ return *logstream::initGlobalLogstream();
}
*/
#ifdef FG_NDEBUG
# define SG_LOG(C,P,M)
-#elif defined( __MWERKS__ )
-# define SG_LOG(C,P,M) ::sglog() << ::loglevel(C,P) << M << std::endl
#else
-# define SG_LOG(C,P,M) sglog() << loglevel(C,P) << M << std::endl
+# define SG_LOG(C,P,M) do { \
+ logstream& __tmplogstreamref(sglog()); \
+ if(__tmplogstreamref.would_log(C,P)) { \
+ __tmplogstreamref << loglevel(C,P) << M << std::endl; } \
+ } while(0)
#endif
-#define SG_STRINGIFY(x) #x
-#define SG_TOSTRING(x) SG_STRINGIFY(x)
-#define SG_ORIGIN __FILE__ ":" SG_TOSTRING(__LINE__)
+#define SG_ORIGIN __FILE__ ":" SG_STRINGIZE(__LINE__)
#endif // _LOGSTREAM_H