00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00043 #ifndef ___APPLOG_H___
00044 #define ___APPLOG_H___
00045
00046 #ifndef CCXX_SLOG_H_
00047 #include <cc++/slog.h>
00048 #endif
00049
00050 #include <cc++/exception.h>
00051
00052 #include <string>
00053 #include <sstream>
00054 #include <iostream>
00055 #include <map>
00056
00057 #ifdef CCXX_NAMESPACES
00058 using namespace std;
00059
00060 namespace ost
00061 {
00062 #endif
00063
00071 class __EXPORT HEXdump
00072 {
00073 protected:
00077 std::string _str;
00078
00079 public:
00080
00089 HEXdump(const unsigned char *buffer, int buff_len, int max_len = 200);
00090
00094 virtual ~HEXdump() { _str = string();}
00095
00100 const char * c_str() const
00101 {
00102 return _str.c_str();
00103 }
00104
00108 std::string str()
00109 {
00110 return _str;
00111 }
00112
00118 friend std::ostream& operator<< (std::ostream& out, const HEXdump &hd)
00119 {
00120 out << hd.c_str();
00121 return out;
00122 }
00123
00124 };
00125
00130 class __EXPORT AppLogException : public ost::Exception
00131 {
00132 public:
00137 AppLogException(const std::string &what_arg) : ost::Exception(what_arg) {};
00138
00139 };
00140
00141 class AppLogPrivate;
00142
00171 class __EXPORT AppLog : protected streambuf, public ostream
00172 {
00173 protected:
00174
00175 AppLogPrivate *d;
00176 void writeLog(bool endOfLine = true);
00177 static map<string, Slog::Level> *assoc;
00178
00179 public:
00183 class __EXPORT Ident
00184 {
00185 private:
00186 std::string _ident;
00187 public:
00188
00192 Ident() {};
00193
00197 ~Ident() {};
00198
00202 Ident(Ident& id) {_ident = id._ident;}
00203
00207 Ident(const char *str) : _ident(str) {};
00208
00212 std::string& str() {return _ident;}
00213
00217 Ident& operator= (std::string &st) {_ident = st; return *this;}
00218
00222 Ident& operator= (const char str[]) {_ident = str; return *this;}
00223
00227 const char* c_str() {return _ident.c_str();}
00228 };
00229
00230 #ifndef WIN32
00231
00238 AppLog(const char* logFileName = NULL, bool logDirectly = false , bool usePipe = false);
00239 #else
00240
00246 AppLog(const char* logFileName = NULL, bool logDirectly = false);
00247 #endif
00248
00251 virtual ~AppLog();
00252
00257 void subscribe();
00258
00262 void unsubscribe();
00263
00264 #ifndef WIN32
00265
00272 void logFileName(const char* FileName, bool logDirectly = false, bool usePipe = false);
00273 #else
00274
00280 void logFileName(const char* FileName, bool logDirectly = false);
00281 #endif
00282
00285 void close(void);
00286
00291 void level(Slog::Level enable);
00292
00297 void clogEnable(bool en = true);
00298
00303 void slogEnable(bool en = true);
00304
00310 void identLevel(const char *ident, Slog::Level level);
00311
00316 void open(const char *ident);
00317
00323 virtual int overflow(int c);
00324
00328 virtual int sync();
00329
00330 #ifdef HAVE_SNPRINTF
00331
00336 void emerg(const char *format, ...);
00337
00342 void alert(const char *format, ...);
00343
00348 void critical(const char *format, ...);
00349
00354 void error(const char *format, ...);
00355
00360 void warn(const char *format, ...);
00361
00366 void notice(const char *format, ...);
00367
00372 void info(const char *format, ...);
00373
00378 void debug(const char *format, ...);
00379 #endif
00380
00387 AppLog &operator()(const char *ident, Slog::Level level = Slog::levelError);
00388
00394 inline AppLog& operator()(Ident &ident)
00395 {
00396 open(ident.c_str());
00397 return *this;
00398 }
00399
00405 AppLog &operator()(Slog::Level level);
00406
00412 AppLog& operator<< (AppLog& (*pfManipulator)(AppLog&));
00413
00419 AppLog& operator<< (ostream& (*pfManipulator)(ostream&));
00420
00421 friend ostream& operator << (ostream &out, AppLog & al)
00422 {
00423 return al;
00424 }
00425
00431 inline AppLog& operator<< (Ident &ident)
00432 {
00433 open(ident.c_str());
00434 return *this;
00435 }
00436
00437
00442 inline AppLog &warn(void)
00443 {return operator()(Slog::levelWarning);}
00444
00449 AppLog &error(void)
00450 { return operator()(Slog::levelError);}
00451
00456 inline AppLog &debug(void)
00457 {return operator()(Slog::levelDebug);}
00458
00463 inline AppLog &emerg(void)
00464 {return operator()(Slog::levelEmergency);}
00465
00470 inline AppLog &alert(void)
00471 {return operator()(Slog::levelAlert);}
00472
00477 inline AppLog &critical(void)
00478 {return operator()(Slog::levelCritical);}
00479
00484 inline AppLog ¬ice(void)
00485 {return operator()(Slog::levelNotice);}
00486
00491 inline AppLog &info(void)
00492 {return operator()(Slog::levelInfo);}
00493
00509 static Slog::Level levelTranslate(string name)
00510 {
00511 map<string, Slog::Level>::iterator it = assoc->find(name);
00512
00513 return (it != assoc->end()) ? it->second : Slog::levelEmergency;
00514 }
00515
00516 };
00517
00523 __EXPORT inline AppLog &debug(AppLog& sl)
00524 {return sl.operator()(Slog::levelDebug);}
00525
00531 __EXPORT inline AppLog &warn(AppLog& sl)
00532 {return sl.operator()(Slog::levelWarning);}
00533
00539 __EXPORT inline AppLog &error(AppLog& sl)
00540 { return sl.operator()(Slog::levelError);}
00541
00547 __EXPORT inline AppLog &emerg(AppLog& sl)
00548 {return sl.operator()(Slog::levelEmergency);}
00549
00555 __EXPORT inline AppLog &alert(AppLog& sl)
00556 {return sl.operator()(Slog::levelAlert);}
00557
00563 __EXPORT inline AppLog &critical(AppLog& sl)
00564 {return sl.operator()(Slog::levelCritical);}
00565
00571 __EXPORT inline AppLog ¬ice(AppLog& sl)
00572 {return sl.operator()(Slog::levelNotice);}
00573
00579 __EXPORT inline AppLog &info(AppLog& sl)
00580 {return sl.operator()(Slog::levelInfo);}
00581
00585 __EXPORT extern AppLog alog;
00586
00587 #ifdef CCXX_NAMESPACES
00588 }
00589 #endif
00590
00591 #endif //___APPLOG_H___