OSG::Log Class Reference
[Log]

#include <OSGLog.h>

Inheritance diagram for OSG::Log:

List of all members.

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
static void terminate (void)
 reconnects the streams for the current settings

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)
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

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 [7]
 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
static Char8 * _buffer = NULL
 holds the nil buffer
static int _buffer_size = 0
 holds the nil buffer

Friends

OSG_BASE_DLLMAPPING void doInitLog (void)
OSG_BASE_DLLMAPPING bool osgExit (void)

Classes

struct  Module
struct  nilbuf

Detailed Description

Message logger class, handles info,warning and error messages

Logging is controlled by several environment variables.

Definition at line 245 of file OSGLog.h.


Member Typedef Documentation

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

Definition at line 361 of file OSGLog.h.


Constructor & Destructor Documentation

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

Definition at line 331 of file OSGLog.cpp.

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

00331                                            :
00332      std::ostream  (_nilbufP == NULL ?
00333                         _nilbufP = new Log::nilbuf() : _nilbufP),
00334     _logType       (logType       ),
00335     _logLevel      (logLevel      ),
00336     _fileStream    (              ),
00337     _logBuf        (              ),
00338     _headerElem    (             0),
00339     _moduleHandling(LOG_MODULE_ALL)
00340 {
00341     if(_nilstreamP == NULL)
00342         _nilstreamP = new std::ostream(_nilbufP);
00343 
00344     for(UInt32 i = 0; i < sizeof(_streamVec)/sizeof(LogOStream *); i++)
00345     {
00346 #ifdef OSG_HAS_NILBUF
00347         _streamVec[i] = new LogOStream(_nilbufP);
00348 #else
00349         _streamVec[i] = new LogOStream(_nilStreamP->rdbuf());
00350 #endif
00351     }
00352 
00353     setHeaderElem(LOG_TYPE_HEADER);
00354 
00355     _refTime = getSystemTime();
00356 
00357     setLogLevel(logLevel);
00358 }

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

Definition at line 363 of file OSGLog.cpp.

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

00363                                                  :
00364      std::ostream  (_nilbufP == NULL ?
00365                         _nilbufP = new Log::nilbuf() : _nilbufP),
00366     _logType       (LOG_FILE      ),
00367     _logLevel      (logLevel      ),
00368     _fileStream    (              ),
00369     _logBuf        (              ),
00370     _headerElem    (             0),
00371     _moduleHandling(LOG_MODULE_ALL)
00372 {
00373     if(_nilstreamP == NULL)
00374         _nilstreamP = new std::ostream(_nilbufP);
00375 
00376     for(UInt32 i = 0; i < sizeof(_streamVec)/sizeof(LogOStream *); i++)
00377     {
00378 #ifdef OSG_HAS_NILBUF
00379         _streamVec[i] = new LogOStream(_nilbufP);
00380 #else
00381         _streamVec[i] = new LogOStream(_nilStreamP->rdbuf());
00382 #endif
00383     }
00384 
00385     _refTime = getSystemTime();
00386 
00387     setHeaderElem(LOG_TYPE_HEADER);
00388     setLogFile   (fileName);
00389     setLogLevel  (logLevel);
00390 }

Log::~Log ( void   )  [virtual]

Definition at line 392 of file OSGLog.cpp.

References _nilbufP, _nilstreamP, _streamVec, and setLogFile().

00393 {
00394     setLogFile(NULL, true);
00395 
00396     delete _nilstreamP;
00397     delete _nilbufP;
00398 
00399     _nilstreamP = NULL;
00400     _nilbufP    = NULL;
00401 
00402     for(UInt32 i = 0; i < sizeof(_streamVec)/sizeof(LogOStream *); i++)
00403     {
00404         delete _streamVec[i];
00405 
00406         _streamVec[i] = NULL;
00407     }
00408 
00409 }

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


Member Function Documentation

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

Definition at line 273 of file OSGLog.h.

Referenced by OSG::osgStartLog().

00273 {;} // TODO: implement

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

Definition at line 274 of file OSGLog.h.

Referenced by OSG::endLog().

00274 {;} // TODO: implement

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

Definition at line 416 of file OSGLog.cpp.

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

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

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

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

Definition at line 434 of file OSGLog.cpp.

References _headerElem, and setHeaderElem().

00435 {
00436     setHeaderElem((_headerElem | elem), force);
00437 }

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

Definition at line 442 of file OSGLog.cpp.

References _headerElem, and setHeaderElem().

00443 {
00444     setHeaderElem((_headerElem & ~elem),force);
00445 }

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

Definition at line 450 of file OSGLog.cpp.

References _headerElem.

00451 {
00452     return (_headerElem & elem) != 0;
00453 }

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

Definition at line 455 of file OSGLog.cpp.

References _moduleHandling.

00457 {
00458     _moduleHandling |= handling;
00459 }

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

Definition at line 461 of file OSGLog.cpp.

References _moduleHandling.

00463 {
00464     _moduleHandling &= ~handling;
00465 }

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

Definition at line 467 of file OSGLog.cpp.

References _moduleList.

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

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

Definition at line 494 of file OSGLog.cpp.

00495 {
00496 }

bool Log::hasModule ( const Char8 *  module  ) 

Definition at line 498 of file OSGLog.cpp.

References _moduleList.

Referenced by checkModule().

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

bool Log::checkModule ( const Char8 *  module  ) 

Definition at line 517 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().

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

LogType Log::getLogType ( void   ) 

Definition at line 555 of file OSGLog.cpp.

References _logType.

00556 {
00557     return _logType;
00558 }

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

Definition at line 564 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::osgStringCaseCmp().

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

LogLevel Log::getLogLevel ( void   ) 

Definition at line 642 of file OSGLog.cpp.

References _logLevel.

00643 {
00644     return _logLevel;
00645 }

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

Set method for attribute logLevel, checks the env vars OSG_LOG_LEVEL_STARTUP and OSG_LOG_LEVEL and uses their value, unless force is true.

Parameters:
[in] logLevel The level for log messages to be emitted.
[in] force If true, ignore env variables and set level to logLevel.

Definition at line 655 of file OSGLog.cpp.

References _logLevel, connect(), OSG::GlobalSystemState, OSG::LOG_DEBUG, OSG::LOG_DEBUG_GV, OSG::LOG_FATAL, OSG::LOG_INFO, OSG::LOG_LOG, OSG::LOG_NOTICE, OSG::LOG_WARNING, OSG::osgLog(), OSG::osgLogP, OSG::osgStringCaseCmp(), and OSG::Startup.

Referenced by Log().

00656 {
00657     static Char8    *levelnames[] =
00658     {
00659         "log",
00660         "fatal",
00661         "warning",
00662         "notice",
00663         "debug_gv",
00664         "info",
00665         "debug",
00666         NULL
00667     };
00668 
00669     static LogLevel  levels    [] =
00670     {
00671         LOG_LOG,
00672         LOG_FATAL,
00673         LOG_WARNING,
00674         LOG_NOTICE,
00675         LOG_DEBUG_GV,
00676         LOG_INFO,
00677         LOG_DEBUG
00678     };
00679 
00680     static Int32 levelCount = sizeof(levels) / sizeof(LogLevel);
00681 
00682     Char8 *el;
00683     Int32  ll;
00684     Int32  i;
00685 
00686     // unless forced, envvars override the argument
00687     if(!force && (this == osgLogP))
00688     {
00689         // startup allows different log level
00690         if(GlobalSystemState == Startup)
00691         {
00692             if((el = getenv("OSG_LOG_LEVEL_STARTUP")) != 0)
00693             {
00694                 // OSG_LOG_LEVEL_STARTUP has highest precedence
00695                 osgLog() << "OSGLog::setLogLevel: overridden by envvar "
00696                          << "OSG_LOG_LEVEL_STARTUP '" << el << "'."
00697                          << std::endl;
00698             }
00699             else if((el = getenv("OSG_LOG_LEVEL")) != 0)
00700             {
00701                 // fallback to OSG_LOG_LEVEL
00702                 osgLog() << "OSGLog::setLogLevel: overridden by envvar "
00703                          << "OSG_LOG_LEVEL '" << el << "'."
00704                          << std::endl;
00705             }
00706         }
00707         else
00708         {
00709             if((el = getenv("OSG_LOG_LEVEL")) != 0)
00710             {
00711                 osgLog() << "OSGLog::setLogLevel: overridden by envvar "
00712                          << "OSG_LOG_LEVEL '" << el << "'."
00713                          << std::endl;
00714             }
00715         }
00716 
00717         // if an envvar was set, interpret its value
00718         if(el != 0)
00719         {
00720             if(sscanf(el, "%d", &ll) != 1)
00721             {
00722                 // interpret the value as name of a level
00723                 for(i = 0; levelnames[i]; ++i)
00724                 {
00725                     if(!osgStringCaseCmp(el, levelnames[i]))
00726                     {
00727                         logLevel = levels[i];
00728                         break;
00729                     }
00730                 }
00731 
00732                 if(!levelnames[i])
00733                 {
00734                     logLevel = LOG_DEBUG;
00735 
00736                     osgLog() << "OSGLog::setLogLevel: Could not interpret "
00737                              << "envvar, setting to LOG_DEBUG."
00738                              << std::endl;
00739                 }
00740             }
00741             else
00742             {
00743                 // interpret value as numerical level
00744                 if(ll < 0)
00745                 {
00746                     ll = 0;
00747                 }
00748                 else if(ll >= levelCount)
00749                 {
00750                     ll = levelCount - 1;
00751                 }
00752 
00753                 logLevel = levels[ll];
00754             }
00755         }
00756     }
00757 
00758     // if force is true this is the unmodified argument, otherwise envvars
00759     // might have changed the value of logLevel
00760     _logLevel = logLevel;
00761     connect();
00762 }

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

Definition at line 108 of file OSGLog.inl.

References _logLevel.

00109 {
00110     return (_logLevel >= level) ? true : false;
00111 }

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

Definition at line 768 of file OSGLog.cpp.

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

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

00769 {
00770     const Char8 *name;
00771 
00772 #ifdef OSG_STREAM_HAS_ISOPEN
00773     if(_fileStream.is_open())
00774 #else
00775     if(_fileStream.rdbuf()->is_open())
00776 #endif
00777     {
00778         _fileStream.close();
00779     }
00780 
00781     if(!force && (this == osgLogP) && (name = getenv("OSG_LOG_FILE")))
00782     {
00783         osgLog() << "Log::setLogFile: overriden by envvar OSG_LOG_FILE '"
00784                  << name << "'." << std::endl;
00785     }
00786     else
00787     {
00788         name = fileName;
00789     }
00790 
00791     if(name && *name)
00792     {
00793         _fileStream.open(name, std::ios::out);
00794 
00795 #ifdef OSG_STREAM_HAS_ISOPEN
00796         if(_fileStream.is_open())
00797 #else
00798         if(_fileStream.rdbuf()->is_open())
00799 #endif
00800         {
00801             _logType = LOG_FILE;
00802             connect();
00803         }
00804     }
00805 }

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

Definition at line 114 of file OSGLog.inl.

References _refTime.

00115 {
00116     return _refTime;
00117 }

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

Definition at line 120 of file OSGLog.inl.

References _refTime.

00121 {
00122     _refTime = refTime;
00123 }

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

Definition at line 126 of file OSGLog.inl.

References _refTime, and OSG::getSystemTime().

00127 {
00128     _refTime = getSystemTime();
00129 }

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

Definition at line 140 of file OSGLog.inl.

References _logBuf.

00141 {
00142   return _logBuf;
00143 }

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

Definition at line 146 of file OSGLog.inl.

References _streamVec.

Referenced by OSG::osgStartLog().

00147 {
00148     return *(_streamVec[level]); 
00149 }

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

Definition at line 152 of file OSGLog.inl.

References _nilstreamP.

Referenced by OSG::osgStartLog().

00153 {
00154     return *_nilstreamP;
00155 }

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

Definition at line 158 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().

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

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

Definition at line 811 of file OSGLog.cpp.

References _buffer, _buffer_size, and OSG::osgMax().

00812 {
00813 
00814     va_list args;
00815 
00816     va_start( args, format );
00817 
00818 #if defined(OSG_HAS_VSNPRINTF) && !defined(__sgi)
00819     int count;
00820 
00821     if(_buffer == NULL)
00822     {
00823         _buffer_size = 8;
00824         _buffer = new Char8[_buffer_size];
00825     }
00826 
00827     // on windows it returns -1 if the output
00828     // was truncated due to the buffer size limit.
00829     // on irix this returns always buffer_size-1 ????
00830 
00831     count = vsnprintf(_buffer, _buffer_size, format, args);
00832 
00833     while(count >= _buffer_size || count == -1)
00834     {
00835         _buffer_size = osgMax(_buffer_size * 2, count + 1);
00836 
00837         if(_buffer != NULL) 
00838             delete [] _buffer;
00839 
00840         _buffer = new Char8[_buffer_size];
00841 
00842         va_start(args, format);
00843 
00844         count = vsnprintf(_buffer, _buffer_size, format, args);
00845     }
00846 #else
00847     if(_buffer_size < 8192)
00848     {
00849         _buffer_size = 8192;
00850 
00851         if(_buffer != NULL) 
00852             delete [] _buffer;
00853 
00854         _buffer = new Char8[_buffer_size];
00855     }
00856 
00857     vsprintf(_buffer, format, args);
00858 #endif
00859 
00860 //    *this << buffer;
00861 //    *this << std::flush;
00862 //  Work around VC71. Patch by Chad Austin.
00863     std::ostream& os = *this;
00864     os << _buffer;
00865     os << std::flush;
00866 
00867 
00868     va_end(args);
00869 }

void Log::connect ( void   )  [protected]

Definition at line 875 of file OSGLog.cpp.

References _fileStream, _logBuf, _logLevel, _logType, _nilbufP, _streamVec, OSG::LOG_BUFFER, OSG::LOG_FILE, OSG::LOG_NONE, OSG::LOG_STDERR, and OSG::LOG_STDOUT.

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

00876 {
00877     Int32 i;
00878 
00879 #ifndef OSG_STREAM_RDBUF_HAS_PARAM
00880     switch(_logType)
00881     {
00882         case LOG_STDOUT:
00883             this->bp = std::cout.rdbuf();
00884             break;
00885         case LOG_STDERR:
00886             this->bp = std::cerr.rdbuf();
00887             break;
00888         case LOG_FILE:
00889             this->bp = _fileStream.rdbuf();
00890             break;
00891         case LOG_BUFFER:
00892             this->bp = _logBuf;
00893             break;
00894         case LOG_NONE:
00895         default</