00001 /*---------------------------------------------------------------------------- 00002 Name: Log.h 00003 Project: xmlBlaster.org 00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file 00005 Comment: Handling the Client data 00006 -----------------------------------------------------------------------------*/ 00007 00008 #ifndef _UTIL_LOG_H 00009 #define _UTIL_LOG_H 00010 00011 #include <util/xmlBlasterDef.h> 00012 #include <util/PropertyDef.h> 00013 #include <util/Property.h> 00014 #include <util/I_Log.h> 00015 00024 namespace org { namespace xmlBlaster { namespace util { 00025 00026 class Dll_Export Log : public I_Log { 00027 00028 private: 00029 00033 Log(const Log& entry); 00034 00038 Log& operator =(const Log& entry); 00039 00040 bool withXtermColor_; 00041 00061 enum {L_NOLOG= 0x0, // No logs at all 00062 L_PANIC= 0x1, // Do exit on error 00063 L_ERROR= 0x2, // Internal error occured 00064 L_WARN = 0x4, // Warning about user actions 00065 L_INFO = 0x8, // Important informational logs only 00066 L_CALL = 0x10, // Trace entry of methods 00067 L_TIME = 0x20, // Show elapsed milliseconds 00068 L_TRACE= 0x40, // Trace application flow 00069 L_DUMP = 0x80, // Dump internal state 00070 L_EXIT = 0x100, // Do a normal exit 00071 L_PLAIN= 0x200 // Marker for plain output 00072 }; 00073 // static int lookAndFeelTime = LC_TIME; 00077 static const char* const ESC ; 00078 static const char* const BOLD ; 00079 static const char* const RED_BLACK ; 00080 static const char* const GREEN_BLACK ; 00081 static const char* const YELLOW_BLACK ; 00082 static const char* const BLUE_BLACK ; 00083 static const char* const PINK_BLACK ; 00084 static const char* const LTGREEN_BLACK; 00085 static const char* const WHITE_BLACK ; 00086 static const char* const WHITE_RED ; 00087 static const char* const BLACK_RED ; 00088 static const char* const BLACK_GREEN ; 00089 static const char* const BLACK_PINK ; 00090 static const char* const BLACK_LTGREEN; 00091 00092 Property& properties_; 00093 int logLevel_; 00094 00098 int numWarnInvocations; 00099 int numErrorInvocations; 00100 std::string currentLogFormat; 00101 bool logFormatPropertyRead; 00102 00103 std::string ME; 00104 std::string name_; 00105 00106 std::string timeE, callE, traceE, plainE, infoE; 00107 std::string warnE, errorE, panicE, exitE; 00108 00113 std::string timeX, callX, traceX, plainX, infoX; 00114 std::string warnX, errorX, panicX, exitX; 00115 00116 private: 00122 int logLevelToBit(const std::string &logLevel) { 00123 if (logLevel == "PANIC") return L_PANIC; 00124 else if (logLevel == "ERROR") return L_ERROR; 00125 else if (logLevel == "WARN" ) return L_WARN; 00126 else if (logLevel == "INFO" ) return L_INFO; 00127 else if (logLevel == "CALL") return L_CALL; 00128 else if (logLevel == "TIME" ) return L_TIME; 00129 else if (logLevel == "TRACE") return L_TRACE; 00130 else if (logLevel == "DUMP" ) return L_DUMP; 00131 return L_NOLOG; 00132 } 00133 00134 void initSpecificTrace(const std::string& trace, const std::string& traceId); 00135 00136 00141 void exitLow(int val); 00142 00143 public: 00145 inline std::string getName() { return name_; } 00146 00147 Log(Property& properties, int args=0, const char * const argc[]=0, const std::string& name="default"); 00148 00149 00150 ~Log(); 00151 00156 void setWithXtermColor(bool val=true); 00157 00161 void setDefaultLogLevel(); 00162 00163 00167 void setLogLevel(int level); 00168 00169 00177 void setLogLevel(int argc, const char * const args[]); 00178 00179 00184 void removeLogLevel(std::string logLevel); 00185 00186 00191 void addLogLevel(std::string logLevel); 00192 00193 00201 void setPreLogLevelCheck(); 00202 00203 00209 std::string bitToLogLevel(int level) const; 00210 00215 std::string getLogLevelStr() const { return bitToLogLevel(logLevel_); } 00216 00220 int getLogLevel() const { 00221 return logLevel_; 00222 } 00223 00224 00225 void setLogFormat(const std::string &format) { 00226 currentLogFormat = format; 00227 } 00228 00229 00233 void panic(const std::string &instance, const std::string &text); 00234 00235 00239 void exit(const std::string &instance, const std::string &text); 00240 00241 00245 void info(const std::string &instance, const std::string &text); 00246 00247 00252 void warn(const std::string &instance, const std::string &text); 00253 00254 00258 void error(const std::string &instance, const std::string &text); 00259 00260 00261 /* 00262 * Log without time/date/instance 00263 * @param instance (not currently used) 00264 * @param text the std::string to log 00265 */ 00266 void plain(const std::string &instance, const std::string &text); 00267 00268 00269 /* 00270 * Log without time/date 00271 */ 00272 void dump(const std::string &instance, const std::string &text); 00273 00274 00278 void trace(const std::string &instance, const std::string &text); 00279 00280 00284 void call(const std::string &instance, const std::string &text); 00285 00286 00290 void time(const std::string &instance, const std::string &text); 00291 00292 00299 virtual std::string usage() const; 00300 00304 void displayStatistics(); 00305 00306 00311 void printStack(); 00312 00313 00319 void initialize(); 00320 00321 00322 std::string getTime(); 00323 00324 00336 void log(const std::string &levelStr, int level, const std::string &instance, 00337 const std::string &text); 00338 00339 00340 Property& getProperties() { 00341 return properties_; 00342 } 00343 00344 }; // end of class Log 00345 00346 00347 00348 }}} // end of namespace util 00349 00350 #endif // _UTIL_LOG_H