Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGLog.inl

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 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 //---------------------------------------------------------------------------
00040 //  Includes
00041 //---------------------------------------------------------------------------
00042 
00043 
00044 #include <stdlib.h>
00045 #include <stdio.h>
00046 
00047 #include "OSGConfig.h"
00048 
00049 #include <iostream>
00050 
00051 OSG_BEGIN_NAMESPACE
00052 
00053 //---------------------------------------------------------------------------
00054 //  LogStream
00055 //---------------------------------------------------------------------------
00056 
00057 inline
00058 LogOStream::LogOStream(std::streambuf *buf) : 
00059     std::ostream(buf) 
00060 {
00061 }
00062 
00063 
00064 inline
00065 LogOStream::~LogOStream(void)
00066 {
00067 }
00068 
00069 inline
00070 void LogOStream::setrdbuf(std::streambuf *buf) 
00071 {
00072 #ifdef OSG_STREAM_RDBUF_HAS_PARAM
00073     std::ostream::rdbuf(buf); 
00074 #else
00075     bp = buf; 
00076 #endif
00077 }
00078 
00079 //---------------------------------------------------------------------------
00080 //  LogBuf
00081 //---------------------------------------------------------------------------
00082 
00083 inline
00084 LogBuf::Chunk::Chunk(void) : 
00085     data(NULL), 
00086     size(   0) 
00087 {
00088 }
00089 
00090 
00091 inline
00092 LogBuf::Chunk::~Chunk(void)
00093 {
00094     delete [] data; 
00095 }
00096 
00097 
00098 inline
00099 bool LogBuf::getEnabled(void)
00100 {
00101     return _enabled; 
00102 }
00103 
00104 
00105 inline
00106 void LogBuf::setEnabled(bool value)
00107 {
00108     _enabled = value; 
00109 }
00110 
00111 //---------------------------------------------------------------------------
00112 //  Log
00113 //---------------------------------------------------------------------------
00114 
00115 inline 
00116 bool Log::checkLevel(LogLevel level)
00117 {
00118     return (_logLevel >= level) ? true : false;
00119 }
00120 
00121 inline
00122 Time Log::getRefTime(void)
00123 {
00124     return _refTime;
00125 }
00126 
00127 inline
00128 void Log::setRefTime(Time refTime)
00129 {
00130     _refTime = refTime;
00131 }
00132 
00133 inline
00134 void Log::resetRefTime(void)
00135 {
00136     _refTime = getSystemTime();
00137 }
00138 
00139 
00140 inline
00141 Log::Module::Module(void) : 
00142     name(NULL), 
00143     isStatic(true) 
00144 {
00145 }
00146 
00147 inline
00148 LogBuf & Log::getLogBuf(void)
00149 {
00150   return _logBuf;
00151 }
00152 
00153 inline
00154 std::ostream &Log::stream(LogLevel level)
00155 {
00156     return *(_streamVec[level]); 
00157 }
00158 
00159 inline
00160 std::ostream &Log::nilstream(void)
00161 {
00162     return *_nilstreamP;
00163 }
00164 
00165 inline 
00166 std::ostream &Log::doHeader(      LogLevel  level, 
00167                             const Char8    *module, 
00168                             const Char8    *file, 
00169                                   UInt32    line)
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             if (color)
00185                 sout << color;          
00186             sout << _levelName[level] << sep;          
00187             if (color)
00188                 sout << resetColor;
00189         }
00190 
00191         if(_headerElem & LOG_TIMESTAMP_HEADER) 
00192             sout << (getSystemTime() - _refTime) << sep;
00193 
00194         if(module && *module && (_headerElem & LOG_MODULE_HEADER))
00195             sout << module << sep;
00196 
00197         if(file && *file && (_headerElem & LOG_FILE_HEADER)) 
00198         {
00199             sout << file;
00200 
00201             if(_headerElem & LOG_LINE_HEADER)
00202                 sout << ":" << line;
00203 
00204                         sout << sep;
00205         }
00206 
00207         if(_headerElem & LOG_END_NEWLINE_HEADER)
00208             sout << std::endl;   
00209         else
00210             sout << ' ';
00211     }
00212 
00213     return sout;
00214 }
00215 
00216 inline 
00217 void initLog(void) 
00218 {
00219     if(osgLogP == NULL)
00220         doInitLog();
00221 }
00222 
00223 inline 
00224 Log &osgLog(void) 
00225 {
00226     initLog();
00227 
00228     return *osgLogP;
00229 }
00230 
00231 inline 
00232 std::ostream &osgStartLog(      bool      logHeader,
00233                                 LogLevel  level, 
00234                           const Char8    *module,
00235                           const Char8    *file, 
00236                                 UInt32    line)
00237 {
00238     initLog();
00239 
00240     osgLogP->lock();
00241 
00242     if(osgLogP->checkModule(module)) 
00243     {
00244         if(logHeader)
00245             osgLogP->doHeader(level,module,file,line);
00246 
00247         return osgLogP->stream(level);
00248     }
00249     else
00250         return osgLogP->nilstream();
00251 }
00252 
00253 inline  
00254 std::ostream &endLog(std::ostream &strm)
00255 {
00256     initLog();
00257 
00258     osgLogP->unlock();
00259     
00260     strm << std::endl;
00261     return strm;
00262 }
00263 
00264 inline 
00265 void indentLog(UInt32 indent, std::ostream &stream)
00266 {
00267     for(UInt32 i = 0; i < indent; i++)
00268     {
00269         stream << " ";
00270     }
00271 }
00272 
00273 OSG_END_NAMESPACE
00274 
00275 

Generated on Thu Aug 25 04:07:09 2005 for OpenSG by  doxygen 1.4.3