OSGLog.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2003 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *         contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de    *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038
00039 #ifndef _OSGLOG_H_
00040 #define _OSGLOG_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044 
00045 #include "OSGBaseTypes.h"
00046 #include "OSGBaseInitFunctions.h"
00047 #include "OSGTime.h"
00048 #include "OSGLock.h"
00049
00050 #include <cstdio>
00051 #include <fstream>
00052 #include <list>
00053
00054
00055 OSG_BEGIN_NAMESPACE
00056
00057 #if defined(__GNUC__)
00058 #define OSG_FUNCNAME_MACRO __PRETTY_FUNCTION__
00059 #elif defined(WIN32)
00060 #define OSG_FUNCNAME_MACRO __FUNCSIG__
00061 #else
00062 #define OSG_FUNCNAME_MACRO "<unknown>"
00063 #endif
00064 
00072 enum LogType
00073 {
00074     LOG_NONE   = 0,
00075     LOG_STDOUT = 1,
00076     LOG_STDERR = 2,
00077     LOG_FILE   = 3,
00078     LOG_BUFFER = 4
00079 };
00080
00084 enum LogLevel
00085 {
00086     LOG_LOG      = 0,
00087     LOG_FATAL    = 1,
00088     LOG_WARNING  = 2,
00089     LOG_NOTICE   = 3,
00090     LOG_DEBUG_GV = 4,
00091     LOG_INFO     = 5,
00092     LOG_DEBUG    = 6
00093 };
00094
00098 enum LogHeaderElem
00099 {
00100     LOG_NONE_HEADER          = 0,
00101     LOG_BEGIN_NEWLINE_HEADER = 1,
00102     LOG_TYPE_HEADER          = 2,
00103     LOG_TIMESTAMP_HEADER     = 4,
00104     LOG_MODULE_HEADER        = 8,
00105     LOG_FILE_HEADER          = 16,
00106     LOG_LINE_HEADER          = 32,
00107     LOG_FUNCNAME_HEADER      = 64,
00108     LOG_END_NEWLINE_HEADER   = 128,
00109     LOG_ASPECT_HEADER        = 256,
00110
00111     LOG_ANSICOLOR_HEADER     = 4096,
00112     LOG_COLOR_HEADER         = 8192,
00113     LOG_TAB_HEADER           = 16384,
00114
00115     LOG_ALL_HEADER           = 32767
00116 };
00117
00122 enum LogModuleHandling
00123 {
00124     LOG_MODULE_NONE           = 0,
00125     LOG_MODULE_KNOWN          = 1,
00126     LOG_MODULE_UNKNOWN        = 2,
00127     LOG_MODULE_UNDEFINED      = 4,
00128     LOG_MODULE_ALL            = 7
00129 };
00130
00137 #ifndef OSG_DEFAULT_LOG_LEVEL
00138 #    define OSG_DEFAULT_LOG_LEVEL LOG_WARNING
00139 #endif
00140 
00141 #ifndef OSG_DEFAULT_LOG_TYPE
00142 #    define OSG_DEFAULT_LOG_TYPE LOG_STDERR
00143 #endif
00144 
00145 #ifndef OSG_DEFAULT_LOG_HEADER_ELEM
00146 #    define OSG_DEFAULT_LOG_HEADER_ELEM LOG_TYPE_HEADER
00147 #endif
00148 
00159 struct OSG_BASE_DLLMAPPING LogOStream : public std::ostream
00160 {
00161   public:
00162
00163     LogOStream(std::streambuf *buf);
00164
00165     virtual ~LogOStream(void);
00166
00167     void setrdbuf(std::streambuf *buf);
00168 };
00169
00177 class OSG_BASE_DLLMAPPING LogBuf : public std::streambuf
00178 {
00179     /*==========================  PUBLIC  =================================*/
00180
00181   public:
00182
00183   // only temporary until the functors work with all compiler
00184
00185     typedef void (*Callback)(const Char8 *data,
00186                                    Int32  size,
00187                                    void  *clientData);
00188
00190     struct Chunk
00191     {
00192         Char8 *data;
00193         Int32  size;
00194
00195         Chunk(void);
00196         ~Chunk(void);
00197     };
00198
00199     /*---------------------------------------------------------------------*/
00203     LogBuf(      UInt32  bufferSize = 1024);
00204     LogBuf(const LogBuf &                 );
00205
00207     /*---------------------------------------------------------------------*/
00211     virtual ~LogBuf();
00212
00214     /*---------------------------------------------------------------------*/
00218     bool getEnabled   (void             );
00219     void setEnabled   (bool value = true);
00220
00221     void clearChunkBag(void             );
00222
00224     /*---------------------------------------------------------------------*/
00228     void setCallback   (Callback  cb,
00229                         void     *clientData = 0,
00230                         bool      flushData  = false);
00231     void removeCallback(void                        );
00232
00233
00235     /*==========================  PRIVATE  ================================*/
00236
00237   private:
00238
00239     bool               _enabled;
00240
00241     std::list<Chunk*>  _chunkBag;
00242
00243     Callback           _callback;
00244     void              *_clientData;
00245
00246     const LogBuf &operator=(const LogBuf          &);
00247           void    write    (const Char8           *buffer,
00248                                   std::streamsize  size  );
00249
00250     /*---------------------------------------------------------------------*/
00254     virtual Int32           overflow(      Int32            c    );
00255     virtual Int32           sync    (      void                  );
00256     virtual std::streamsize xsputn  (const Char8           *buffer,
00257                                            std::streamsize  size);
00258
00259 };
00260
00277 class OSG_BASE_DLLMAPPING Log : public std::ostream
00278 {
00279     /*==========================  PUBLIC  =================================*/
00280
00281   public:
00282
00283     /*---------------------------------------------------------------------*/
00287     Log(      LogType   logType  = LOG_STDERR,
00288               LogLevel  logLevel = LOG_NOTICE);
00289
00290     Log(const Char8    *fileName,
00291               LogLevel  logLevel = LOG_NOTICE);
00292
00294     /*---------------------------------------------------------------------*/
00298     virtual ~Log(void);
00299
00301     /*---------------------------------------------------------------------*/
00305     static bool initLock    (void);
00306
00307     static bool finalizeLock(void);
00308
00309            void lock        (void);
00310            void unlock      (void);
00311
00313     /*---------------------------------------------------------------------*/
00317     virtual void setHeaderElem    (      UInt32             elemMask,
00318                                          bool               force    = false);
00319     virtual void addHeaderElem    (      LogHeaderElem      elem,
00320                                          bool               force    = false);
00321     virtual void delHeaderElem    (      LogHeaderElem      elem,
00322                                          bool               force    = false);
00323     virtual bool hasHeaderElem    (      LogHeaderElem      elem);
00324
00325     virtual void addModuleHandling(      LogModuleHandling  handling,
00326                                          bool               force    = false);
00327     virtual void delModuleHandling(      LogModuleHandling  handling,
00328                                          bool               force    = false);
00329
00330     virtual void addModuleName    (const Char8             *module,
00331                                          bool               isStatic = false);
00332     virtual void delModuleName    (const Char8             *module          );
00333
00334             bool hasModule        (const Char8             *module          );
00335             bool checkModule      (const Char8             *module          );
00336
00338     /*---------------------------------------------------------------------*/
00342     LogType  getLogType  (      void                                  );
00343     void     setLogType  (      LogType   logType,  bool force = false);
00344
00345     LogLevel getLogLevel (      void);
00346     void     setLogLevel (      LogLevel  logLevel, bool force = false);
00347     bool     checkLevel  (      LogLevel  logLevel                    );
00348
00349     void     setLogFile  (const Char8    *fileName, bool force = false);
00350
00351     Time     getRefTime  (      void                                  );
00352     void     setRefTime  (      Time  refTime                         );
00353     void     resetRefTime(      void                                  );
00354
00356     /*---------------------------------------------------------------------*/
00360     LogBuf       &getLogBuf(void          );
00361
00362     std::ostream &stream   (LogLevel level);
00363     std::ostream &nilstream(void          );
00364
00366     /*---------------------------------------------------------------------*/
00370     std::ostream &doHeader(      LogLevel  level,
00371                            const Char8    *module,
00372                            const Char8    *file,
00373                                  UInt32    line,
00374                            const Char8    *funcName   );
00375
00376     void          doLog   (const Char8    *format, ...);
00377
00379     /*=========================  PROTECTED  ===============================*/
00380
00381   protected:
00382
00383     /*---------------------------------------------------------------------*/
00387     void connect    (void                           );
00388
00389     bool colorHeader(LogLevel level, const char *sep);
00390
00391     static void terminate(void);
00392
00394     /*===========================  PRIVATE  ===============================*/
00395
00396   private:
00397
00398     typedef std::ostream Inherited;
00399
00400     friend OSG_BASE_DLLMAPPING void doInitLog(void);
00401     friend OSG_BASE_DLLMAPPING bool osgExit  (void);
00402
00403     /*---------------------------------------------------------------------*/
00408     struct OSG_BASE_DLLMAPPING nilbuf : public std::streambuf
00409     {
00410     };
00411
00413     struct Module
00414     {
00415         const Char8 *name;
00416               bool   isStatic;
00417
00418         Module(void);
00419     };
00420
00422     /*---------------------------------------------------------------------*/
00426     static       nilbuf          *_nilbufP;
00427     static       std::ostream    *_nilstreamP;
00428
00429     static const Char8           *_levelName [];
00430     static const Char8           *_levelColor[];
00431
00432     static       Char8           *_buffer;
00433     static       int              _bufferSize;
00434
00435     static       LockRefPtr       _pLogLock;
00436     static       InitFuncWrapper  _lockInit;
00437
00439     /*---------------------------------------------------------------------*/
00443     LogType            _logType;
00444     LogLevel           _logLevel;
00445
00446     std::fstream       _fileStream;
00447
00448     LogBuf             _logBuf;
00449     LogOStream        *_streamVec[7];
00450
00451     UInt32             _headerElem;
00452     UInt32             _moduleHandling;
00453
00454
00455     std::list<Module>  _moduleList;
00456
00457     Time               _refTime;
00458
00460     /*---------------------------------------------------------------------*/
00464     Log(const Log &source);
00465
00467     /*---------------------------------------------------------------------*/
00471     void operator =(const Log &source);
00472
00474 };
00475
00476 typedef Log *LogP;
00477
00484 class OSG_BASE_DLLMAPPING LogLock
00485 {
00486     /*==========================  PUBLIC  =================================*/
00487
00488   public:
00489
00490     /*---------------------------------------------------------------------*/
00494     LogLock(std::ostream &os);
00495
00497     /*---------------------------------------------------------------------*/
00501     ~LogLock(void);
00502
00504     /*---------------------------------------------------------------------*/
00508     inline               operator std::ostream &(void);
00509     inline std::ostream &getStream              (void);
00510
00512     /*===========================  PRIVATE  ===============================*/
00513
00514   private:
00515
00516     std::ostream &_os;
00517 };
00518
00519 #ifndef OSG_LOG_MODULE
00520 #define OSG_LOG_MODULE "OpenSG"
00521 #endif
00522 
00523 extern OSG_BASE_DLLMAPPING LogP osgLogP;
00524
00531 OSG_BASE_DLLMAPPING
00532 void          doInitLog  (      void                   );
00533
00536 inline
00537 void          initLog    (      void                   );
00538
00541 inline
00542 OSG::Log     &osgLog     (      void                   );
00543
00546 inline
00547 std::ostream &osgStartLog(      bool           logHeader,
00548                                 OSG::LogLevel  level,
00549                           const OSG::Char8    *module,
00550                           const OSG::Char8    *file,
00551                                 OSG::UInt32    line,
00552                           const OSG::Char8    *funcName );
00553
00556 inline
00557 std::ostream &endLog      (     std::ostream  &strm     );
00558
00561 inline
00562 void          indentLog   (     OSG::UInt32    indent,
00563                                 std::ostream  &stream   );
00573 #define SLOG                                                       \
00574     OSG::LogLock(OSG::osgStartLog(true,                            \
00575                                   OSG::LOG_LOG,                    \
00576                                   OSG_LOG_MODULE,                  \
00577                                   __FILE__,                        \
00578                                   __LINE__,                        \
00579                                   OSG_FUNCNAME_MACRO)).getStream()
00580 
00584 #define SFATAL                                                          \
00585     OSG::LogLock(OSG::osgStartLog(true,                                 \
00586                                   OSG::LOG_FATAL,                       \
00587                                   OSG_LOG_MODULE,                       \
00588                                   __FILE__,                             \
00589                                   __LINE__,                             \
00590                                   OSG_FUNCNAME_MACRO)).getStream()
00591 
00595 #define SWARNING                                                    \
00596     OSG::LogLock(OSG::osgStartLog(true,                             \
00597                                   OSG::LOG_WARNING,                 \
00598                                   OSG_LOG_MODULE,                   \
00599                                   __FILE__,                         \
00600                                   __LINE__,                         \
00601                                   OSG_FUNCNAME_MACRO)).getStream()
00602 
00606 #define SNOTICE                                                    \
00607     OSG::LogLock(OSG::osgStartLog(true,                            \
00608                                   OSG::LOG_NOTICE,                 \
00609                                   OSG_LOG_MODULE,                  \
00610                                   __FILE__,                        \
00611                                   __LINE__,                        \
00612                                   OSG_FUNCNAME_MACRO)).getStream()
00613 
00617 #define SINFO                                                      \
00618     OSG::LogLock(OSG::osgStartLog(true,                            \
00619                                   OSG::LOG_INFO,                   \
00620                                   OSG_LOG_MODULE,                  \
00621                                   __FILE__,                        \
00622                                   __LINE__,                        \
00623                                   OSG_FUNCNAME_MACRO)).getStream()
00624 
00634 #define PLOG                                                       \
00635     OSG::LogLock(OSG::osgStartLog(false,                           \
00636                                   OSG::LOG_LOG,                    \
00637                                   OSG_LOG_MODULE,                  \
00638                                   __FILE__,                        \
00639                                   __LINE__,                        \
00640                                   OSG_FUNCNAME_MACRO)).getStream()
00641 
00645 #define PFATAL                                                     \
00646     OSG::LogLock(OSG::osgStartLog(false,                           \
00647                                   OSG::LOG_FATAL,                  \
00648                                   OSG_LOG_MODULE,                  \
00649                                   __FILE__,                        \
00650                                   __LINE__,                        \
00651                                   OSG_FUNCNAME_MACRO)).getStream()
00652 
00656 #define PWARNING                                                     \
00657     OSG::LogLock(OSG::osgStartLog(false,                             \
00658                                   OSG::LOG_WARNING,                  \
00659                                   OSG_LOG_MODULE,                    \
00660                                   __FILE__,                          \
00661                                   __LINE__,                          \
00662                                   OSG_FUNCNAME_MACRO)).getStream()
00663 
00667 #define PNOTICE                                                    \
00668     OSG::LogLock(OSG::osgStartLog(false,                           \
00669                                   OSG::LOG_NOTICE,                 \
00670                                   OSG_LOG_MODULE,                  \
00671                                   __FILE__,                        \
00672                                   __LINE__,                        \
00673                                   OSG_FUNCNAME_MACRO)).getStream()
00674 
00678 #define PINFO                                                      \
00679     OSG::LogLock(OSG::osgStartLog(false,                           \
00680                                   OSG::LOG_INFO,                   \
00681                                   OSG_LOG_MODULE,                  \
00682                                   __FILE__,                        \
00683                                   __LINE__,                        \
00684                                   OSG_FUNCNAME_MACRO)).getStream()
00685 
00692 // C interface, because it can be compiled away
00693 // don't use varargs macros, because they are not supported everywhere
00694 // use the (( )) convention instead
00695
00699 #define FLOG(par)                                               \
00700 {                                                               \
00701     if(OSG::GlobalSystemState <= OSG::Shutdown)                 \
00702     {                                                           \
00703         OSG::initLog();                                         \
00704         OSG::osgLogP->lock();                                   \
00705         OSG::osgStartLog(true,                                  \
00706                          OSG::LOG_LOG,                          \
00707                          OSG_LOG_MODULE,                        \
00708                          __FILE__,                              \
00709                          __LINE__,                              \
00710                          OSG_FUNCNAME_MACRO);                   \
00711         OSG::osgLogP->doLog par;                                \
00712         OSG::osgLogP->unlock();                                 \
00713     }                                                           \
00714     else                                                        \
00715     {                                                           \
00716         std::printf par;                                        \
00717     }                                                           \
00718 }
00719 
00723 #define FFATAL(par)                                             \
00724 {                                                               \
00725     if(OSG::GlobalSystemState <= OSG::Shutdown)                 \
00726     {                                                           \
00727         OSG::initLog();                                         \
00728         if(OSG::osgLogP->checkLevel(OSG::LOG_FATAL))            \
00729         {                                                       \
00730             OSG::osgLogP->lock();                               \
00731             OSG::osgStartLog(true,                              \
00732                              OSG::LOG_FATAL,                    \
00733                              OSG_LOG_MODULE,                    \
00734                              __FILE__,                          \
00735                              __LINE__,                          \
00736                              OSG_FUNCNAME_MACRO);               \
00737             OSG::osgLogP->doLog par;                            \
00738             OSG::osgLogP->unlock();                             \
00739         }                                                       \
00740     }                                                           \
00741     else                                                        \
00742     {                                                           \
00743         std::printf par;                                        \
00744     }                                                           \
00745 }
00746 
00750 #define FWARNING(par)                                           \
00751 {                                                               \
00752     if(OSG::GlobalSystemState <= OSG::Shutdown)                 \
00753     {                                                           \
00754         OSG::initLog();                                         \
00755         if(OSG::osgLogP->checkLevel(OSG::LOG_WARNING))          \
00756         {                                                       \
00757             OSG::osgLogP->lock();                               \
00758             OSG::osgStartLog(true,                              \
00759                              OSG::LOG_WARNING,                  \
00760                              OSG_LOG_MODULE,                    \
00761                              __FILE__,                          \
00762                              __LINE__,                          \
00763                              OSG_FUNCNAME_MACRO);               \
00764             OSG::osgLogP->doLog par;                            \
00765             OSG::osgLogP->unlock();                             \
00766         }                                                       \
00767     }                                                           \
00768     else                                                        \
00769     {                                                           \
00770         std::printf par;                                        \
00771     }                                                           \
00772 }
00773 
00777 #define FNOTICE(par)                                                \
00778 {                                                                   \
00779     if(OSG::GlobalSystemState <= OSG::Shutdown)                     \
00780     {                                                               \
00781         OSG::initLog();                                             \
00782         if(OSG::osgLogP->checkLevel(OSG::LOG_NOTICE))               \
00783         {                                                           \
00784             OSG::osgLogP->lock();                                   \
00785             OSG::osgStartLog(true,                                  \
00786                              OSG::LOG_NOTICE,                       \
00787                              OSG_LOG_MODULE,                        \
00788                              __FILE__,                              \
00789                              __LINE__,                              \
00790                              OSG_FUNCNAME_MACRO);                   \
00791             OSG::osgLogP->doLog par;                                \
00792             OSG::osgLogP->unlock();                                 \
00793         }                                                           \
00794     }                                                               \
00795     else                                                            \
00796     {                                                               \
00797         std::printf par;                                            \
00798     }                                                               \
00799 }
00800 
00804 #define FINFO(par)                                              \
00805 {                                                               \
00806     if(OSG::GlobalSystemState <= OSG::Shutdown)                 \
00807     {                                                           \
00808         OSG::initLog();                                         \
00809         if(OSG::osgLogP->checkLevel(OSG::LOG_INFO))             \
00810         {                                                       \
00811             OSG::osgLogP->lock();                               \
00812             OSG::osgStartLog(true,                              \
00813                              OSG::LOG_INFO,                     \
00814                              OSG_LOG_MODULE,                    \
00815                              __FILE__,                          \
00816                              __LINE__,                          \
00817                              OSG_FUNCNAME_MACRO);               \
00818             OSG::osgLogP->doLog par;                            \
00819             OSG::osgLogP->unlock();                             \
00820         }                                                       \
00821     }                                                           \
00822     else                                                        \
00823     {                                                           \
00824         std::printf par;                                        \
00825     }                                                           \
00826 }
00827 
00831 #ifdef OSG_DEBUG
00832 #define FDEBUG(par)                                             \
00833 {                                                               \
00834     if(OSG::GlobalSystemState <= OSG::Shutdown)                 \
00835     {                                                           \
00836         OSG::initLog();                                         \
00837         if(OSG::osgLogP->checkLevel(OSG::LOG_DEBUG))            \
00838         {                                                       \
00839             OSG::osgLogP->lock();                               \
00840             OSG::osgStartLog(true,                              \
00841                              OSG::LOG_DEBUG,OSG_LOG_MODULE,     \
00842                              __FILE__,                          \
00843                              __LINE__,                          \
00844                              OSG_FUNCNAME_MACRO);               \
00845             OSG::osgLogP->doLog par;                            \
00846             OSG::osgLogP->unlock();                             \
00847         }                                                       \
00848     }                                                           \
00849     else                                                        \
00850     {                                                           \
00851         std::printf par;                                        \
00852     }                                                           \
00853 }
00854 #else
00855 #define FDEBUG(par)
00856 #endif
00857 
00861 #ifdef OSG_DEBUG
00862 #define FDEBUG_GV(par)                                              \
00863 {                                                                   \
00864     if(OSG::GlobalSystemState <= OSG::Shutdown)                     \
00865     {                                                               \
00866         OSG::initLog();                                             \
00867         if(OSG::osgLogP->checkLevel(OSG::LOG_DEBUG_GV))             \
00868         {                                                           \
00869             OSG::osgLogP->lock();                                   \
00870             OSG::osgStartLog(true,                                  \
00871                              OSG::LOG_DEBUG_GV,OSG_LOG_MODULE,      \
00872                              __FILE__,                              \
00873                              __LINE__,                              \
00874                              OSG_FUNCNAME_MACRO);                   \
00875             OSG::osgLogP->doLog par;                                \
00876             OSG::osgLogP->unlock();                                 \
00877         }                                                           \
00878     }                                                               \
00879     else                                                            \
00880     {                                                               \
00881         std::printf par;                                            \
00882     }                                                               \
00883 }
00884 #else
00885 #define FDEBUG_GV(par)
00886 #endif
00887 
00891 #define FASSERT(condition, doExit)                              \
00892 {                                                               \
00893     if (!condition)                                             \
00894     {                                                           \
00895         OSG::osgLog().lock();                                   \
00896         OSG::osgLog().stream(OSG::LOG_FATAL)                    \
00897             << OSG_LOG_MODULE                                   \
00898             << ':'                                              \
00899             << __FILE__                                         \
00900             << ':'                                              \
00901             << __LINE__                                         \
00902             << " FATAL ASSERT: "                                \
00903             << (doExit ? "exit system" : "try to keep running") \
00904             << std::flush << std::endl;                         \
00905         OSG::osgLog().unlock();                                 \
00906         if(doExit)                                              \
00907             exit(-1);                                           \
00908     }                                                           \
00909 }
00910 
00914 #define FFASSERT(condition, doExit, par)                        \
00915 {                                                               \
00916     if(!condition)                                              \
00917     {                                                           \
00918         OSG::osgLog().lock();                                   \
00919         OSG::osgLog().stream(OSG::LOG_FATAL)                    \
00920             << OSG_LOG_MODULE                                   \
00921             << ':'                                              \
00922             << __FILE__                                         \
00923             << ':'                                              \
00924             << __LINE__                                         \
00925             << " FATAL ASSERT: "                                \
00926             << (doExit ? "exit system" : "try to keep running") \
00927             << std::flush << std::endl;                         \
00928         OSG::osgLogP->doLog par                                 \
00929         OSG::osgLog().unlock();                                 \
00930         if(doExit)                                              \
00931             exit(-1);                                           \
00932     }                                                           \
00933 }
00934 
00941 // C interface without line start outputs
00942
00946 #define FPLOG(par)                                              \
00947 {                                                               \
00948     if(OSG::GlobalSystemState <= OSG::Shutdown)                 \
00949     {                                                           \
00950         OSG::initLog();                                         \
00951         OSG::osgLogP->lock();                                   \
00952         OSG::osgStartLog(false,                                 \
00953                          OSG::LOG_LOG,                          \
00954                          OSG_LOG_MODULE,                        \
00955                          __FILE__,                              \
00956                          __LINE__,                              \
00957                          OSG_FUNCNAME_MACRO);                   \
00958         OSG::osgLogP->doLog par;                                \
00959         OSG::osgLogP->unlock();                                 \
00960     }                                                           \
00961     else                                                        \
00962     {                                                           \
00963         std::printf par;                                        \
00964     }                                                           \
00965 }
00966 
00970 #define FPFATAL(par)                                            \
00971 {                                                               \
00972     if(OSG::GlobalSystemState <= OSG::Shutdown)                 \
00973     {                                                           \
00974         OSG::initLog();                                         \
00975         if(OSG::osgLogP->checkLevel(OSG::LOG_FATAL))            \
00976         {                                                       \
00977             OSG::osgLogP->lock();                               \
00978             OSG::osgStartLog(false,                             \
00979                              OSG::LOG_FATAL,                    \
00980                              OSG_LOG_MODULE,                    \
00981                              __FILE__,                          \
00982                              __LINE__,                          \
00983                              OSG_FUNCNAME_MACRO);               \
00984             OSG::osgLogP->doLog par;                            \
00985             OSG::osgLogP->unlock();                             \
00986         }                                                       \
00987     }                                                           \
00988     else                                                        \
00989     {                                                           \
00990         std::printf par;                                        \
00991     }                                                           \
00992 }
00993 
00997 #define FPWARNING(par)                                          \
00998 {                                                               \
00999     if(OSG::GlobalSystemState <= OSG::Shutdown)                 \
01000     {                                                           \
01001         OSG::initLog();                                         \
01002         if(OSG::osgLogP->checkLevel(OSG::LOG_WARNING))          \
01003         {                                                       \
01004             OSG::osgLogP->lock();                               \
01005             OSG::osgStartLog(false,                             \
01006                              OSG::LOG_WARNING,                  \
01007                              OSG_LOG_MODULE,                    \
01008                              __FILE__,                          \
01009                              __LINE__,                          \
01010                              OSG_FUNCNAME_MACRO);               \
01011             OSG::osgLogP->doLog par;                            \
01012             OSG::osgLogP->unlock();                             \
01013         }                                                       \
01014     }                                                           \
01015     else                                                        \
01016     {                                                           \
01017         std::printf par;                                        \
01018     }                                                           \
01019 }
01020 
01024 #define FPNOTICE(par)                                           \
01025 {                                                               \
01026     if(OSG::GlobalSystemState <= OSG::Shutdown)                 \
01027     {                                                           \
01028         OSG::initLog();                                         \
01029         if(OSG::osgLogP->checkLevel(OSG::LOG_NOTICE))           \
01030         {                                                       \
01031             OSG::osgLogP->lock();                               \
01032             OSG::osgStartLog(false,                             \
01033                              OSG::LOG_NOTICE,                   \
01034                              OSG_LOG_MODULE,                    \
01035                              __FILE__,                          \
01036                              __LINE__,                          \
01037                              OSG_FUNCNAME_MACRO);               \
01038             OSG::osgLogP->doLog par;                            \
01039             OSG::osgLogP->unlock();                             \
01040         }                                                       \
01041     }                                                           \
01042     else                                                        \
01043     {                                                           \
01044         std::printf par;                                        \
01045     }                                                           \
01046 }
01047 
01051 #define FPINFO(par)                                             \
01052 {                                                               \
01053     if(OSG::GlobalSystemState <= OSG::Shutdown)                 \
01054     {                                                           \
01055         OSG::initLog();                                         \
01056         if(OSG::osgLogP->checkLevel(OSG::LOG_INFO))             \
01057         {                                                       \
01058             OSG::osgLogP->lock();                               \
01059             OSG::osgStartLog(false,                             \
01060                              OSG::LOG_INFO,                     \
01061                              OSG_LOG_MODULE,                    \
01062                              __FILE__,                          \
01063                              __LINE__,                          \
01064                              OSG_FUNCNAME_MACRO);               \
01065             OSG::osgLogP->doLog par;                            \
01066             OSG::osgLogP->unlock();                             \
01067         }                                                       \
01068     }                                                           \
01069     else                                                        \
01070     {                                                           \
01071         std::printf par;                                        \
01072     }                                                           \
01073 }
01074 
01078 #ifdef OSG_DEBUG
01079 #define FPDEBUG(par)                                            \
01080 {                                                               \
01081     if(OSG::GlobalSystemState <= OSG::Shutdown)                 \
01082     {                                                           \
01083         OSG::initLog();                                         \
01084         if(OSG::osgLogP->checkLevel(OSG::LOG_DEBUG))            \
01085         {                                                       \
01086             OSG::osgLogP->lock();                               \
01087             OSG::osgStartLog(false,                             \
01088                              OSG::LOG_DEBUG,OSG_LOG_MODULE,     \
01089                              __FILE__,                          \
01090                              __LINE__,                          \
01091                              OSG_FUNCNAME_MACRO);               \
01092             OSG::osgLogP->doLog par;                            \
01093             OSG::osgLogP->unlock();                             \
01094         }                                                       \
01095     }                                                           \
01096     else                                                        \
01097     {                                                           \
01098         std::printf par;                                        \
01099     }                                                           \
01100 }
01101 #else
01102 #define FPDEBUG(par)
01103 #endif
01104 
01105 #ifdef OSG_DEBUG
01106 #define FPDEBUG_GV(par)                                         \
01107 {                                                               \
01108     if(OSG::GlobalSystemState <= OSG::Shutdown)                 \
01109     {                                                           \
01110         OSG::initLog();                                         \
01111         if(OSG::osgLogP->checkLevel(OSG::LOG_DEBUG_GV))         \
01112         {                                                       \
01113             OSG::osgLogP->lock();                               \
01114             OSG::osgStartLog(false,                             \
01115                              OSG::LOG_DEBUG_GV,OSG_LOG_MODULE,  \
01116                              __FILE__,                          \
01117                              __LINE__,                          \
01118                              OSG_FUNCNAME_MACRO);               \
01119             OSG::osgLogP->doLog par;                            \
01120             OSG::osgLogP->unlock();                             \
01121         }                                                       \
01122     }                                                           \
01123     else                                                        \
01124     {                                                           \
01125         std::printf par;                                        \
01126     }                                                           \
01127 }
01128 #else
01129 #define FPDEBUG_GV(par)
01130 #endif
01131 
01134 OSG_END_NAMESPACE
01135
01136 #include "OSGLog.inl"
01137
01138 #endif /* _OSGLOG_H_ */