Visualization Library v1.0.3A lightweight C++ OpenGL middleware for 2D/3D graphics |
[Download] [Tutorials] [All Classes] [Grouped Classes] |
00001 /**************************************************************************************/ 00002 /* */ 00003 /* Visualization Library */ 00004 /* http://visualizationlibrary.org */ 00005 /* */ 00006 /* Copyright (c) 2005-2010, Michele Bosi */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without modification, */ 00010 /* are permitted provided that the following conditions are met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, this */ 00013 /* list of conditions and the following disclaimer. */ 00014 /* */ 00015 /* - Redistributions in binary form must reproduce the above copyright notice, this */ 00016 /* list of conditions and the following disclaimer in the documentation and/or */ 00017 /* other materials provided with the distribution. */ 00018 /* */ 00019 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */ 00020 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 00021 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ 00022 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */ 00023 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ 00024 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 00025 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ 00026 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ 00027 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 00028 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00029 /* */ 00030 /**************************************************************************************/ 00031 00032 #ifndef Log_INCLUDE_ONCE 00033 #define Log_INCLUDE_ONCE 00034 00035 #include <vlCore/String.hpp> 00036 #include <vlCore/IMutex.hpp> 00037 #include <fstream> 00038 00039 namespace vl 00040 { 00041 //------------------------------------------------------------------------------ 00042 // Log 00043 //----------------------------------------------------------------------------- 00045 class VLCORE_EXPORT Log: public Object 00046 { 00047 VL_INSTRUMENT_ABSTRACT_CLASS(vl::Log, Object) 00048 00049 public: 00050 Log() 00051 { 00052 VL_DEBUG_SET_OBJECT_NAME() 00053 mLogLevel = LL_LogPrint; // only used by operator<<() 00054 } 00055 00056 Log& operator<<( ELogLevel log_level ) { mLogLevel = log_level; return *this; } 00057 00058 Log& operator<<( const String& str ) 00059 { 00060 switch(mLogLevel) 00061 { 00062 case LL_LogNotify: notify(str); break; 00063 case LL_LogPrint: print(str); break; 00064 case LL_LogBug: bug(str); break; 00065 case LL_LogError: error(str); break; 00066 case LL_LogWarning: warning(str); break; 00067 case LL_LogDebug: debug(str); break; 00068 } 00069 return *this; 00070 } 00071 00072 Log& operator<<( const std::string& v ) 00073 { 00074 *this << String::fromStdString(v); 00075 return *this; 00076 } 00077 00078 Log& operator<<( const void* v ) 00079 { 00080 *this << String::fromPointer(v); 00081 return *this; 00082 } 00083 00084 Log& operator<<( const char* v ) 00085 { 00086 *this << String(v); 00087 return *this; 00088 } 00089 00090 Log& operator<<( char v ) 00091 { 00092 *this << String(v); 00093 return *this; 00094 } 00095 00096 Log& operator<<( unsigned char v ) 00097 { 00098 *this << String::fromUInt(v); 00099 return *this; 00100 } 00101 00102 Log& operator<<( short v ) 00103 { 00104 *this << String::fromInt(v); 00105 return *this; 00106 } 00107 00108 Log& operator<<( unsigned short v ) 00109 { 00110 *this << String::fromUInt(v); 00111 return *this; 00112 } 00113 00114 Log& operator<<( int v ) 00115 { 00116 *this << String::fromInt(v); 00117 return *this; 00118 } 00119 00120 Log& operator<<( unsigned int v ) 00121 { 00122 *this << String::fromUInt(v); 00123 return *this; 00124 } 00125 00126 Log& operator<<( long v ) 00127 { 00128 *this << String::fromLongLong(v); 00129 return *this; 00130 } 00131 00132 Log& operator<<( unsigned long v ) 00133 { 00134 *this << String::fromULongLong(v); 00135 return *this; 00136 } 00137 00138 Log& operator<<( long long v ) 00139 { 00140 *this << String::fromLongLong(v); 00141 return *this; 00142 } 00143 00144 Log& operator<<( unsigned long long v ) 00145 { 00146 *this << String::fromULongLong(v); 00147 return *this; 00148 } 00149 00150 Log& operator<<( double v ) 00151 { 00152 *this << String::fromDouble(v); 00153 return *this; 00154 } 00155 00156 Log& operator<<( float v ) 00157 { 00158 *this << String::fromDouble(v); 00159 return *this; 00160 } 00161 00162 protected: 00163 virtual void printImplementation(ELogLevel level, const String& message) = 0; 00164 00165 ELogLevel mLogLevel; // only used by operator<<() 00166 00167 // --- static methods --- 00168 00169 public: 00172 static void setLogMutex(IMutex* mutex) { mLogMutex = mutex; } 00173 00175 static IMutex* logMutex() { return mLogMutex; } 00176 00180 static void notify(const String& message); 00181 00184 static void print(const String& message); 00185 00188 static void debug(const String& message); 00189 00192 static void warning(const String& message); 00193 00196 static void error(const String& message); 00197 00200 static void bug(const String& message); 00201 00203 static void logSystemInfo(); 00204 00205 private: 00206 static IMutex* mLogMutex; 00207 }; 00208 00209 //----------------------------------------------------------------------------- 00210 // Default logger 00211 //----------------------------------------------------------------------------- 00213 VLCORE_EXPORT void setDefLogger(Log* logger); 00214 00216 VLCORE_EXPORT Log* defLogger(); 00217 00218 // Log macros 00219 #define VL_LOG (*::vl::defLogger()) 00220 #define VL_LOG_NOTIFY (VL_LOG << ::vl::LL_LogNotify) 00221 #define VL_LOG_PRINT (VL_LOG << ::vl::LL_LogPrint) 00222 #define VL_LOG_BUG (VL_LOG << ::vl::LL_LogBug) 00223 #define VL_LOG_ERROR (VL_LOG << ::vl::LL_LogError) 00224 #define VL_LOG_WARNING (VL_LOG << ::vl::LL_LogWarning) 00225 #define VL_LOG_DEBUG (VL_LOG << ::vl::LL_LogDebug) 00226 00227 //----------------------------------------------------------------------------- 00228 // StandardLog 00229 //----------------------------------------------------------------------------- 00231 class VLCORE_EXPORT StandardLog: public Log 00232 { 00233 VL_INSTRUMENT_CLASS(vl::StandardLog, Log) 00234 00235 public: 00236 void setLogFile(const String& file); 00237 const String& logFile() const { return mLogFile; } 00238 00239 protected: 00240 virtual void printImplementation(ELogLevel level, const String& message); 00241 String mLogFile; 00242 std::ofstream mFile; 00243 }; 00244 } 00245 00246 #endif