osg::Log Class Reference
[Log]

#include <OSGLog.h>

List of all members.

Public Member Functions

Constructors


 Log (LogType logType=LOG_STDERR, LogLevel logLevel=LOG_NOTICE)
 Log (const Char8 *fileName, LogLevel logLevel=LOG_NOTICE)
 Constructor which takes a log file name.
Destructors


virtual ~Log (void)
Class Specific


void lock (void)
void unlock (void)
Module Handling


virtual void setHeaderElem (UInt32 elemMask, bool force=false)
 set method for attribute _headerElem
virtual void addHeaderElem (LogHeaderElem elem, bool force=false)
 add method for attribute _headerElem
virtual void delHeaderElem (LogHeaderElem elem, bool force=false)
 delete method for attribute _headerElem
virtual bool hasHeaderElem (LogHeaderElem elem)
 check for a single headerElem
virtual void addModuleHandling (LogModuleHandling handling, bool force=false)
 set method for attribute _headerElem
virtual void delModuleHandling (LogModuleHandling handling, bool force=false)
 set method for attribute _headerElem
virtual void addModuleName (const Char8 *module, bool isStatic=false)
 set method for attribute _headerElem
virtual void delModuleName (const Char8 *module)
 set method for attribute _headerElem
bool hasModule (const Char8 *module)
 set method for attribute _headerElem
bool checkModule (const Char8 *module)
 set method for attribute _headerElem
Level, Type and Time Handling


LogType getLogType (void)
void setLogType (LogType logType, bool force=false)
 set method for attribute logType, checks OSG_LOG_TYPE env var if not forced.
LogLevel getLogLevel (void)
void setLogLevel (LogLevel logLevel, bool force=false)
 set method for attribute logLevel, checks OSG_LOG_LEVEL env var if not forced.
bool checkLevel (LogLevel logLevel)
void setLogFile (const Char8 *fileName, bool force=false)
 method to set and activate the log file, checks OSG_LOG_FILE env var if not forced
Time getRefTime (void)
void setRefTime (Time refTime)
void resetRefTime (void)
Stream Handling


LogBufgetLogBuf (void)
std::ostream & stream (LogLevel level)
std::ostream & nilstream (void)
Logging


std::ostream & doHeader (LogLevel level, const Char8 *module, const Char8 *file, UInt32 line)
void doLog (const Char8 *format,...)
 print for C-interface helper method

Protected Member Functions

Class Specific


void connect (void)
 reconnects the streams for the current settings
bool colorHeader (LogLevel level, const char *sep)
 colorHeader which takes the log level for level color

Private Types

typedef std::ostream Inherited

Private Member Functions

Constructors


 Log (const Log &source)
Operators


void operator= (const Log &source)

Private Attributes

Static Fields
LogType _logType
 holds the log type
LogLevel _logLevel
 holds the log level
std::fstream _fileStream
 file stream
LogBuf _logBuf
 holds the log type
LogOStream_streamVec [6]
 stream vector
UInt32 _headerElem
 holds the log type
UInt32 _moduleHandling
 holds the log type
std::list< Module_moduleList
 holds the log type
Time _refTime
 holds the log type

Static Private Attributes

Static Fields
static nilbuf_nilbufP = NULL
 holds the nil buffer
static std::ostream * _nilstreamP = NULL
 holds the nil buffer
static const Char8_levelName []
 holds the nil buffer
static const Char8_levelColor []
 holds the nil buffer

Friends

void doInitLog (void)

Classes

struct  Module
struct  nilbuf


Detailed Description

Message logger class, handles info,warning and error messages

Definition at line 224 of file OSGLog.h.


Member Typedef Documentation

typedef std::ostream osg::Log::Inherited [private]

Definition at line 338 of file OSGLog.h.


Constructor & Destructor Documentation

Log::Log ( LogType  logType = LOG_STDERR,
LogLevel  logLevel = LOG_NOTICE 
)

Definition at line 342 of file OSGLog.cpp.

References _nilbufP, _nilstreamP, _refTime, _streamVec, osg::getSystemTime(), osg::LOG_TYPE_HEADER, setHeaderElem(), and setLogLevel().

00342                                            :
00343      std::ostream  (_nilbufP == NULL ? 
00344                         _nilbufP = new Log::nilbuf() : _nilbufP), 
00345     _logType       (logType       ), 
00346     _logLevel      (logLevel      ), 
00347     _fileStream    (              ),
00348     _logBuf        (              ),
00349     _headerElem    (             0),
00350     _moduleHandling(LOG_MODULE_ALL)
00351 {   
00352     if(_nilstreamP == NULL)
00353         _nilstreamP = new std::ostream(_nilbufP);
00354 
00355     for(UInt32 i = 0; i < sizeof(_streamVec)/sizeof(LogOStream *); i++)
00356     {
00357 #ifdef OSG_HAS_NILBUF
00358         _streamVec[i] = new LogOStream(_nilbufP);
00359 #else
00360         _streamVec[i] = new LogOStream(_nilStreamP->rdbuf());
00361 #endif
00362     }
00363 
00364     setHeaderElem(LOG_TYPE_HEADER);
00365 
00366     _refTime = getSystemTime();
00367 
00368     setLogLevel(logLevel);
00369 }

Log::Log ( const Char8 fileName,
LogLevel  logLevel = LOG_NOTICE 
)

Definition at line 374 of file OSGLog.cpp.

References _nilbufP, _nilstreamP, _refTime, _streamVec, osg::getSystemTime(), osg::LOG_TYPE_HEADER, setHeaderElem(), setLogFile(), and setLogLevel().

00374                                                  :
00375      std::ostream  (_nilbufP == NULL ? 
00376                         _nilbufP = new Log::nilbuf() : _nilbufP), 
00377     _logType       (LOG_FILE      ), 
00378     _logLevel      (logLevel      ), 
00379     _fileStream    (              ),
00380     _logBuf        (              ),
00381     _headerElem    (             0),
00382     _moduleHandling(LOG_MODULE_ALL)
00383 {
00384     if(_nilstreamP == NULL)
00385         _nilstreamP = new std::ostream(_nilbufP);
00386 
00387     for(UInt32 i = 0; i < sizeof(_streamVec)/sizeof(LogOStream *); i++)
00388     {
00389 #ifdef OSG_HAS_NILBUF
00390         _streamVec[i] = new LogOStream(_nilbufP);
00391 #else
00392         _streamVec[i] = new LogOStream(_nilStreamP->rdbuf());
00393 #endif
00394     }
00395 
00396     _refTime = getSystemTime();
00397 
00398     setHeaderElem(LOG_TYPE_HEADER);
00399     setLogFile   (fileName);
00400     setLogLevel  (logLevel);
00401 }

Log::~Log ( void   )  [virtual]

Definition at line 403 of file OSGLog.cpp.

References setLogFile().

00404 {
00405     setLogFile(NULL, true);
00406 }

osg::Log::Log ( const Log source  )  [private]


Member Function Documentation

void osg::Log::lock ( void   )  [inline]

Definition at line 252 of file OSGLog.h.

Referenced by osg::osgStartLog().

00252 {;} // TODO: implement

void osg::Log::unlock ( void   )  [inline]

Definition at line 253 of file OSGLog.h.

Referenced by osg::endLog().

00253 {;} // TODO: implement

void Log::setHeaderElem ( UInt32  elemMask,
bool  force = false 
) [virtual]

Definition at line 413 of file OSGLog.cpp.

References _headerElem, osg::endLog(), osg::osgLog(), and osg::osgLogP.

Referenced by addHeaderElem(), delHeaderElem(), and Log().

00414 {
00415     Char8 *env;
00416 
00417     if(!force && (this == osgLogP) && (env = getenv( "OSG_LOG_HEADER" )))
00418     {
00419         osgLog() << "Log::setHeaderElem: overriden by envvar OSG_LOG_HEADER '" 
00420                  << env << "'." << endLog;  
00421 
00422         elemMask = LogHeaderElem(atoi(env));
00423     }
00424 
00425     _headerElem = elemMask;
00426 }

void Log::addHeaderElem ( LogHeaderElem  elem,
bool  force = false 
) [virtual]

Definition at line 431 of file OSGLog.cpp.

References _headerElem, and setHeaderElem().

00432 {
00433     setHeaderElem((_headerElem | elem), force);
00434 }

void Log::delHeaderElem ( LogHeaderElem  elem,
bool  force = false 
) [virtual]

Definition at line 439 of file OSGLog.cpp.

References _headerElem, and setHeaderElem().

00440 {
00441     setHeaderElem((_headerElem & ~elem),force);
00442 }

bool Log::hasHeaderElem ( LogHeaderElem  elem  )  [virtual]

Definition at line 447 of file OSGLog.cpp.

References _headerElem.

00448 {
00449     return (_headerElem & elem) != 0;
00450 }

void Log::addModuleHandling ( LogModuleHandling  handling,
bool  force = false 
) [virtual]

Definition at line 452 of file OSGLog.cpp.

References _moduleHandling.

00454 {
00455     _moduleHandling |= handling;
00456 }

void Log::delModuleHandling ( LogModuleHandling  handling,
bool  force = false 
) [virtual]

Definition at line 458 of file OSGLog.cpp.

References _moduleHandling.

00460 {
00461     _moduleHandling &= ~handling;
00462 }

void Log::addModuleName ( const Char8 module,
bool  isStatic = false 
) [virtual]

Definition at line 464 of file OSGLog.cpp.

References _moduleList.

00465 {
00466     Module m;
00467     int    len;
00468 
00469     if(module && *module) 
00470     {
00471         _moduleList.push_back(m);
00472 
00473         if(isStatic) 
00474         {
00475             _moduleList.back().name     = module;
00476             _moduleList.back().isStatic = true;
00477         }
00478         else 
00479         {
00480             len = strlen(module);
00481 
00482             _moduleList.back().name = new Char8[len + 1];
00483 
00484             strcpy(const_cast<Char8 *>(_moduleList.back().name), module);
00485 
00486             _moduleList.back().isStatic = false;            
00487         }
00488     }
00489 }

void Log::delModuleName ( const Char8 module  )  [virtual]

Definition at line 491 of file OSGLog.cpp.

00492 {
00493 }

bool Log::hasModule ( const Char8 module  ) 

Definition at line 495 of file OSGLog.cpp.

References _moduleList.

Referenced by checkModule().

00496 {
00497     bool                        retCode = false;
00498     std::list<Module>::iterator mI;
00499 
00500     if(module && *module) 
00501     {
00502         for(  mI = _moduleList.begin();
00503               retCode || (mI != _moduleList.end()); 
00504             ++mI) 
00505         {
00506             retCode = (mI->isStatic) ? 
00507                 (module == mI->name) : (!strcmp(module,mI->name));
00508         }
00509     }
00510 
00511     return retCode;
00512 }

bool Log::checkModule ( const Char8 module  ) 

Definition at line 514 of file OSGLog.cpp.

References _moduleHandling, hasModule(), osg::LOG_MODULE_ALL, osg::LOG_MODULE_KNOWN, osg::LOG_MODULE_NONE, osg::LOG_MODULE_UNDEFINED, and osg::LOG_MODULE_UNKNOWN.

Referenced by osg::osgStartLog().

00515 {
00516     bool                        retCode = false;
00517     std::list<Module>::iterator mI;
00518 
00519     if(_moduleHandling != LOG_MODULE_NONE) 
00520     {
00521         if(_moduleHandling == LOG_MODULE_ALL) 
00522         {
00523             retCode = true;
00524         }
00525         else
00526         {
00527             if(module && &module) 
00528             {
00529                 if(hasModule(module))
00530                 {
00531                     if(_moduleHandling & LOG_MODULE_KNOWN)
00532                         retCode = true;
00533                 }
00534                 else 
00535                 {
00536                     if(_moduleHandling & LOG_MODULE_UNKNOWN)
00537                         retCode = true;
00538                 }
00539             }
00540             else
00541             {
00542                 if(_moduleHandling & LOG_MODULE_UNDEFINED)
00543                     retCode = true;
00544             }
00545         }
00546     }
00547 
00548     return retCode;
00549 }

LogType Log::getLogType ( void   ) 

Definition at line 552 of file OSGLog.cpp.

References _logType.

00553 { 
00554     return _logType; 
00555 }

void Log::setLogType ( LogType  logType,
bool  force = false 
)

Definition at line 561 of file OSGLog.cpp.

References _logType, connect(), osg::LOG_BUFFER, osg::LOG_FILE, osg::LOG_NONE, osg::LOG_STDERR, osg::LOG_STDOUT, osg::osgLog(), osg::osgLogP, and osg::stringcasecmp().

00562 {
00563     static Char8   *typenames[] = 
00564     {
00565         "none", 
00566         "-",
00567         "stdout", 
00568         "stderr", 
00569         "file",
00570         "buffer",
00571         NULL
00572     };
00573 
00574     static LogType  types    [] = 
00575     {
00576         LOG_NONE, 
00577         LOG_STDOUT, 
00578         LOG_STDOUT, 
00579         LOG_STDERR, 
00580         LOG_FILE,
00581         LOG_BUFFER
00582     };
00583 
00584     static Int32 typeCount = sizeof(types) / sizeof(LogType);
00585 
00586     Char8 *et;
00587     Int32  lt;
00588     Int32  i;                               
00589 
00590     if(!force && (this == osgLogP) && (et = getenv("OSG_LOG_TYPE")))
00591     {
00592         osgLog() << "Log::setLogType: overriden by envvar OSG_LOG_TYPE '" 
00593                  << et << "'." << std::endl; 
00594 
00595         if(sscanf(et, "%d", &lt) != 1)
00596         {               
00597             for(i = 0; typenames[i]; i++)
00598             {
00599                 if(!stringcasecmp(et, typenames[i]))
00600                 {
00601                     _logType = types[i];
00602                     break;
00603                 }
00604             }
00605 
00606             if(! typenames[i])
00607             {
00608                 _logType = LOG_STDERR;
00609 
00610                 osgLog() << "Log::setLogType: couldn't interpret envvar, "
00611                          << "set to LOG_STDERR!" 
00612                          << std::endl; 
00613             }
00614         }
00615         else 
00616         {
00617             if(lt < 0)
00618             {
00619                 lt = 0;
00620             }
00621             else 
00622             {
00623                 if(lt >= typeCount)
00624                     lt = typeCount - 1;
00625             }
00626 
00627             _logType = types[lt];
00628         }
00629     }
00630     else
00631     {
00632         _logType = logType; 
00633     }
00634 
00635     connect(); 
00636 }

LogLevel Log::getLogLevel ( void   ) 

Definition at line 639 of file OSGLog.cpp.

References _logLevel.

00640 {
00641     return _logLevel; 
00642 }

void Log::setLogLevel ( LogLevel  logLevel,
bool  force = false 
)

Definition at line 649 of file OSGLog.cpp.

References _logLevel, connect(), osg::LOG_DEBUG, osg::LOG_FATAL, osg::LOG_INFO, osg::LOG_LOG, osg::LOG_NOTICE, osg::LOG_WARNING, osg::osgLog(), osg::osgLogP, and osg::stringcasecmp().

Referenced by Log().

00650 { 
00651     static Char8    *levelnames[] = 
00652     {
00653         "log", 
00654         "fatal", 
00655         "warning", 
00656         "notice", 
00657         "info", 
00658         "debug", 
00659         NULL 
00660     };
00661 
00662     static LogLevel  levels    [] = 
00663     {
00664         LOG_LOG, 
00665         LOG_FATAL,
00666         LOG_WARNING, 
00667         LOG_NOTICE,
00668         LOG_INFO,
00669         LOG_DEBUG
00670     };
00671 
00672     static Int32 levelCount = sizeof(levels) / sizeof(LogLevel);
00673 
00674     Char8 *el;
00675     Int32  ll;
00676     Int32  i;                               
00677 
00678     if(!force && (this == osgLogP) && (el = getenv("OSG_LOG_LEVEL")))
00679     {
00680         osgLog() << "OSGLog::setLogLevel: overriden by envvar OSG_LOG_LEVEL '" 
00681                  << el << "'." << std::endl; 
00682 
00683         if(sscanf(el, "%d", &ll) != 1)
00684         {
00685             for(i = 0; levelnames[i]; i++)
00686             {
00687                 if(!stringcasecmp(el, levelnames[i]))
00688                 {
00689                     _logLevel = levels[i];
00690                     break;
00691                 }
00692             }
00693 
00694             if(! levelnames[i])
00695             {
00696                 _logLevel = LOG_DEBUG;
00697 
00698                 osgLog() << "Log::setLogLevel: couldn't interpret envvar, "
00699                          << "set to LOG_DEBUG!"
00700                          << std::endl; 
00701             }
00702         }
00703         else 
00704         {
00705             if (ll < 0)
00706             {
00707                 ll = 0;
00708             }
00709             else 
00710             {
00711                 if (ll >= levelCount)
00712                     ll = levelCount - 1;
00713             }
00714 
00715             _logLevel = levels[ll];
00716         }
00717     }
00718     else
00719     {
00720         _logLevel = logLevel; 
00721     }    
00722 
00723     connect() ; 
00724 }

bool osg::Log::checkLevel ( LogLevel  logLevel  )  [inline]

Definition at line 116 of file OSGLog.inl.

References _logLevel.

00117 {
00118     return (_logLevel >= level) ? true : false;
00119 }

void Log::setLogFile ( const Char8 fileName,
bool  force = false 
)

Definition at line 731 of file OSGLog.cpp.

References _fileStream, _logType, connect(), osg::LOG_FILE, osg::osgLog(), and osg::osgLogP.

Referenced by Log(), and ~Log().

00732 {
00733     const Char8 *name;
00734 
00735 #ifdef OSG_STREAM_HAS_ISOPEN
00736     if(_fileStream.is_open())
00737 #else
00738     if(_fileStream.rdbuf()->is_open())
00739 #endif
00740     {
00741         _fileStream.close();
00742     }
00743 
00744     if(!force && (this == osgLogP) && (name = getenv("OSG_LOG_FILE"))) 
00745     {
00746         osgLog() << "Log::setLogFile: overriden by envvar OSG_LOG_FILE '" 
00747                  << name << "'." << std::endl;                            
00748     }
00749     else
00750     {
00751         name = fileName;
00752     }
00753 
00754     if(name && *name) 
00755     {
00756         _fileStream.open(name, std::ios::out);
00757 
00758 #ifdef OSG_STREAM_HAS_ISOPEN
00759         if(_fileStream.is_open()) 
00760 #else
00761         if(_fileStream.rdbuf()->is_open())
00762 #endif
00763         {
00764             _logType = LOG_FILE;
00765             connect();
00766         }
00767     }
00768 }

Time osg::Log::getRefTime ( void   )  [inline]

Definition at line 122 of file OSGLog.inl.

References _refTime.

00123 {
00124     return _refTime;
00125 }

void osg::Log::setRefTime ( Time  refTime  )  [inline]

Definition at line 128 of file OSGLog.inl.

References _refTime.

00129 {
00130     _refTime = refTime;
00131 }

void osg::Log::resetRefTime ( void   )  [inline]

Definition at line 134 of file OSGLog.inl.

References _refTime, and osg::getSystemTime().

00135 {
00136     _refTime = getSystemTime();
00137 }

LogBuf & osg::Log::getLogBuf ( void   )  [inline]

Definition at line 148 of file OSGLog.inl.

References _logBuf.

00149 {
00150   return _logBuf;
00151 }

std::ostream & osg::Log::stream ( LogLevel  level  )  [inline]

Definition at line 154 of file OSGLog.inl.

References _streamVec.

Referenced by osg::osgStartLog(), and osg::SceneFileType::print().

00155 {
00156     return *(_streamVec[level]); 
00157 }

std::ostream & osg::Log::nilstream ( void   )  [inline]

Definition at line 160 of file OSGLog.inl.

References _nilstreamP.

Referenced by osg::osgStartLog().

00161 {
00162     return *_nilstreamP;
00163 }

std::ostream & osg::Log::doHeader ( LogLevel  level,
const Char8 module,
const Char8 file,
UInt32  line 
) [inline]

Definition at line 166 of file OSGLog.inl.

References _headerElem, _levelColor, _levelName, _refTime, _streamVec, colorHeader(), osg::getSystemTime(), osg::LOG_BEGIN_NEWLINE_HEADER, osg::LOG_COLOR_HEADER, osg::LOG_END_NEWLINE_HEADER, osg::LOG_FILE_HEADER, osg::LOG_LINE_HEADER, osg::LOG_MODULE_HEADER, osg::LOG_TAB_HEADER, osg::LOG_TIMESTAMP_HEADER, and osg::LOG_TYPE_HEADER.

Referenced by osg::osgStartLog().

00170 {
00171     LogOStream &sout = *(_streamVec[level]);
00172     const char *sep   = ( (_headerElem & LOG_TAB_HEADER) ? "\t" : ": " );
00173     const char *color = ( (_headerElem & LOG_COLOR_HEADER) ?
00174                            _levelColor[level] : 0 );
00175     const char *resetColor = "\x1b[0m";
00176     
00177     if(_headerElem) 
00178     {
00179         if(_headerElem & LOG_BEGIN_NEWLINE_HEADER)
00180             sout << std::endl;   
00181 
00182         if(_headerElem & LOG_TYPE_HEADER) 
00183         {
00184     #ifdef WIN32
00185             if ( !color || !colorHeader(level, sep) )
00186                 sout << _levelName[level] << sep;
00187     #else
00188             if (color)
00189                 sout << color;          
00190             sout << _levelName[level] << sep;          
00191             if (color)
00192                 sout << resetColor;
00193     #endif
00194         }
00195 
00196         if(_headerElem & LOG_TIMESTAMP_HEADER) 
00197             sout << (getSystemTime() - _refTime) << sep;
00198 
00199         if(module && *module && (_headerElem & LOG_MODULE_HEADER))
00200             sout << module << sep;
00201 
00202         if(file && *file && (_headerElem & LOG_FILE_HEADER)) 
00203         {
00204             sout << file;
00205 
00206             if(_headerElem & LOG_LINE_HEADER)
00207                 sout << ":" << line;
00208 
00209                         sout << sep;
00210         }
00211 
00212         if(_headerElem & LOG_END_NEWLINE_HEADER)
00213             sout << std::endl;   
00214         else
00215             sout << ' ';
00216     }
00217 
00218     return sout;
00219 }

void Log::doLog ( const Char8 format,
  ... 
)

Definition at line 774 of file OSGLog.cpp.

References osg::osgMax().

00775 {
00776     static Char8   *buffer = NULL;
00777     static int      buffer_size = 0;
00778     va_list args;
00779     
00780     va_start( args, format );
00781 
00782 #if defined(OSG_HAS_VSNPRINTF) && !defined(__sgi)
00783     int count;
00784     
00785     if(!buffer)
00786     {
00787         buffer_size = 8;
00788         buffer = new Char8[buffer_size];
00789     }
00790     
00791     // on windows it returns -1 if the output
00792     // was truncated due to the buffer size limit.
00793     // on irix this returns always buffer_size-1 ????
00794     count = vsnprintf(buffer, buffer_size, format, args);
00795     
00796     while(count >= buffer_size || count == -1)
00797     {
00798         buffer_size = osgMax(buffer_size * 2, count + 1);
00799         if(buffer) delete [] buffer;
00800         buffer = new Char8[buffer_size];
00801         va_start( args, format );
00802         count = vsnprintf(buffer, buffer_size, format, args);
00803     }
00804 #else
00805     if(buffer_size < 8192)
00806     {
00807         buffer_size = 8192;
00808         if(buffer) delete [] buffer;
00809         buffer = new Char8[buffer_size];
00810     }
00811     vsprintf(buffer, format, args);
00812 #endif
00813 
00814     //*this << buffer;
00815     //*this << std::flush;
00816     // Work around VC71. Patch by Chad Austin.
00817     std::ostream& os = *this;
00818     os << buffer;
00819     os << std::flush;
00820  
00821     va_end(args);
00822 }

void Log::connect ( void   )  [protected]

Definition at line 828 of file OSGLog.cpp.

References _fileStream, _logBuf, _logLevel, _logType, _nilbufP, _streamVec, osg::LOG_BUFFER, osg::LOG_FILE, osg::LOG_NONE, osg::LOG_STDERR, osg::LOG_STDOUT, and osg::LogOStream::setrdbuf().

Referenced by setLogFile(), setLogLevel(), and setLogType().

00829 {
00830     Int32 i;
00831 
00832 #ifndef OSG_STREAM_RDBUF_HAS_PARAM
00833     switch(_logType) 
00834     {
00835         case LOG_STDOUT:
00836             this->bp = std::cout.rdbuf();
00837             break;
00838         case LOG_STDERR:
00839             this->bp = std::cerr.rdbuf();
00840             break;
00841         case LOG_FILE:
00842             this->bp = _fileStream.rdbuf();
00843             break;
00844         case LOG_BUFFER:
00845             this->bp = _logBuf;
00846             break;
00847         case LOG_NONE:
00848         default:
00849             this->bp = _nilStreamP->rdbuf();
00850             break;
00851     }
00852 #else
00853     switch(_logType) 
00854     {
00855         case LOG_STDOUT:
00856             this->rdbuf(std::cout.rdbuf());
00857             break;
00858         case LOG_STDERR:
00859             this->rdbuf(std::cerr.rdbuf());
00860             break;
00861         case LOG_FILE:
00862             this->rdbuf(_fileStream.rdbuf());
00863             break;
00864         case LOG_BUFFER:
00865             this->rdbuf(&_logBuf);
00866             break;
00867         case LOG_NONE:
00868         default:
00869             this->rdbuf(_nilbufP);
00870             break;
00871     }
00872 #endif
00873 
00874     for(i = 0; i < int(sizeof(_streamVec)/sizeof(std::ostream*)); ++i) 
00875     {
00876         if (i <= _logLevel)
00877         {
00878             _streamVec[i]->setrdbuf(this->rdbuf());
00879         }
00880         else
00881         {
00882 #ifdef OSG_HAS_NILBUF
00883             _streamVec[i]->setrdbuf(_nilbufP);
00884 #else
00885             _streamVec[i]->setrdbuf(_nilStreamP->rdbuf());
00886 #endif
00887         }
00888     }
00889 }

bool Log::colorHeader ( LogLevel  level,
const char *  sep 
) [protected]

Definition at line 275 of file OSGLog.cpp.

References _levelName, _logType, osg::LOG_FATAL, osg::LOG_STDERR, osg::LOG_STDOUT, and osg::LOG_WARNING.

Referenced by doHeader().

00276 {
00277 #if defined (OSG_WIN_TYPES) && !defined(OSG_NO_WINDOWD_H_INCLUDE)
00278     bool ok = true;
00279     std::string str("");
00280     LPSTR colStr;
00281     DWORD cWritten; 
00282     WORD oldColAttrs, colAttrs;
00283     CONSOLE_SCREEN_BUFFER_INFO csbiInfo; 
00284     HANDLE hOutput = INVALID_HANDLE_VALUE;
00285     
00286     switch (_logType) 
00287     {
00288         case LOG_STDERR:
00289             hOutput = GetStdHandle(STD_ERROR_HANDLE);
00290             break;
00291         case LOG_STDOUT:
00292             hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
00293             break;
00294         default:
00295             break;
00296     }
00297     
00298     if ( hOutput == INVALID_HANDLE_VALUE ||
00299         !GetConsoleScreenBufferInfo(hOutput, &csbiInfo) ) 
00300     {
00301         ok = false;
00302     }
00303     else 
00304     {
00305         oldColAttrs = csbiInfo.wAttributes; 
00306         
00307         switch (level) 
00308         {
00309             case LOG_FATAL:
00310                 colAttrs = FOREGROUND_RED | FOREGROUND_INTENSITY;
00311                 break;
00312             case LOG_WARNING:
00313                 colAttrs = FOREGROUND_RED | FOREGROUND_GREEN;
00314                 break;
00315             default:
00316                 colAttrs = oldColAttrs;
00317                 break;
00318         }
00319 
00320         if(_levelName[level] != NULL)
00321             str = _levelName[level];
00322         if(sep != NULL)
00323             str += sep;
00324     
00325         colStr = (LPSTR)str.c_str();
00326         
00327         if ( !SetConsoleTextAttribute(hOutput, colAttrs) ||
00328              !WriteFile(hOutput, colStr, lstrlen(colStr), &cWritten, NULL) ||  
00329              !SetConsoleTextAttribute(hOutput, oldColAttrs) )
00330         {
00331             ok = false;
00332         }
00333     }
00334     
00335     return ok;
00336 #endif
00337     
00338     return false;
00339 }

void osg::Log::operator= ( const Log source  )  [private]


Friends And Related Function Documentation

void doInitLog ( void   )  [friend]

Definition at line 916 of file OSGLog.cpp.

Referenced by osg::initLog().

00917 {
00918 #ifdef OSG_HAS_NILBUF
00919     if(Log::_nilbufP == NULL)
00920         Log::_nilbufP = new Log::nilbuf();
00921 #else
00922     if(Log::_nilstreamP == NULL)
00923         Log::_nilstreamP = new std::fstream("/dev/null", std::ios::out);
00924 #endif
00925 
00926     if(osgLogP == NULL)
00927     {
00928         osgLogP = new Log();
00929 
00930         osgLogP->setLogLevel(OSG_DEFAULT_LOG_LEVEL);
00931         osgLogP->setLogFile (NULL                 );
00932         osgLogP->setLogType (OSG_DEFAULT_LOG_TYPE );
00933     }
00934 }


Member Data Documentation

Log::nilbuf * Log::_nilbufP = NULL [static, private]

Definition at line 365 of file OSGLog.h.

Referenced by connect(), and Log().

std::ostream * Log::_nilstreamP = NULL [static, private]

Definition at line 366 of file OSGLog.h.

Referenced by osg::doInitLog(), Log(), and nilstream().

const Char8 * Log::_levelName [static, private]

Initial value:

 
{
    "LOG", 
        "FATAL", 
        "WARNING", 
        "NOTICE", 
        "INFO", 
        "DEBUG", 
        0
}

Definition at line 368 of file OSGLog.h.

Referenced by colorHeader(), and doHeader().

const Char8 * Log::_levelColor [static, private]

Initial value:

 
{
    0,          
        "\x1b[31m", 
        "\x1b[33m", 
        0,          
        0,          
        0,          
        0
}

Definition at line 369 of file OSGLog.h.

Referenced by doHeader().

Definition at line 376 of file OSGLog.h.

Referenced by colorHeader(), connect(), getLogType(), setLogFile(), and setLogType().

Definition at line 377 of file OSGLog.h.

Referenced by checkLevel(), connect(), getLogLevel(), and setLogLevel().

fstream Log::_fileStream [private]

Definition at line 379 of file OSGLog.h.

Referenced by connect(), and setLogFile().

Definition at line 381 of file OSGLog.h.

Referenced by connect(), and getLogBuf().

LogOStream * Log::_streamVec[6] [private]

Definition at line 382 of file OSGLog.h.

Referenced by connect(), doHeader(), Log(), and stream().

Definition at line 384 of file OSGLog.h.

Referenced by addHeaderElem(), delHeaderElem(), doHeader(), hasHeaderElem(), and setHeaderElem().

Definition at line 385 of file OSGLog.h.

Referenced by addModuleHandling(), checkModule(), and delModuleHandling().

std::list<Module> osg::Log::_moduleList [private]

Definition at line 388 of file OSGLog.h.

Referenced by addModuleName(), and hasModule().

Definition at line 390 of file OSGLog.h.

Referenced by doHeader(), getRefTime(), Log(), resetRefTime(), and setRefTime().


The documentation for this class was generated from the following files:

Generated on Mon Mar 17 12:03:15 2008 for OpenSG by  doxygen 1.5.5