Go to the documentation of this file.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
00126 #ifdef CCXX_EXCEPTIONS
00127
00131 class __EXPORT AppLogException : public ost::Exception
00132 {
00133 public:
00138 AppLogException(const std::string &what_arg) : ost::Exception(what_arg) {};
00139
00140 };
00141 #endif
00142
00143 class AppLogPrivate;
00144
00173 class __EXPORT AppLog : protected streambuf, public ostream
00174 {
00175 protected:
00176
00177 AppLogPrivate *d;
00178 void writeLog(bool endOfLine = true);
00179 static map<string, Slog::Level> *assoc;
00180
00181 public:
00185 class __EXPORT Ident
00186 {
00187 private:
00188 std::string _ident;
00189 public:
00190
00194 Ident() {};
00195
00199 ~Ident() {};
00200
00204 Ident(Ident& id) {_ident = id._ident;}
00205
00209 Ident(const char *str) : _ident(str) {};
00210
00214 std::string& str() {return _ident;}
00215
00219 Ident& operator= (std::string &st) {_ident = st; return *this;}
00220
00224 Ident& operator= (const char str[]) {_ident = str; return *this;}
00225
00229 const char* c_str() {return _ident.c_str();}
00230 };
00231
00232 #ifndef WIN32
00233
00240 AppLog(const char* logFileName = NULL, bool logDirectly = false , bool usePipe = false);
00241 #else
00242
00248 AppLog(const char* logFileName = NULL, bool logDirectly = false);
00249 #endif
00250
00253 virtual ~AppLog();
00254
00259 void subscribe();
00260
00264 void unsubscribe();
00265
00266 #ifndef WIN32
00267
00274 void logFileName(const char* FileName, bool logDirectly = false, bool usePipe = false);
00275 #else
00276
00282 void logFileName(const char* FileName, bool logDirectly = false);
00283 #endif
00284
00287 void close(void);
00288
00293 void level(Slog::Level enable);
00294
00299 void clogEnable(bool en = true);
00300
00305 void slogEnable(bool en = true);
00306
00312 void identLevel(const char *ident, Slog::Level level);
00313
00318 void open(const char *ident);
00319
00325 virtual int overflow(int c);
00326
00330 virtual int sync();
00331
00332 #ifdef HAVE_SNPRINTF
00333
00338 void emerg(const char *format, ...);
00339
00344 void alert(const char *format, ...);
00345
00350 void critical(const char *format, ...);
00351
00356 void error(const char *format, ...);
00357
00362 void warn(const char *format, ...);
00363
00368 void notice(const char *format, ...);
00369
00374 void info(const char *format, ...);
00375
00380 void debug(const char *format, ...);
00381 #endif
00382
00389 AppLog &operator()(const char *ident, Slog::Level level = Slog::levelError);
00390
00396 inline AppLog& operator()(Ident &ident)
00397 {
00398 open(ident.c_str());
00399 return *this;
00400 }
00401
00407 AppLog &operator()(Slog::Level level);
00408
00414 AppLog& operator<< (AppLog& (*pfManipulator)(AppLog&));
00415
00421 AppLog& operator<< (ostream& (*pfManipulator)(ostream&));
00422
00423 friend ostream& operator << (ostream &out, AppLog & al)
00424 {
00425 return al;
00426 }
00427
00433 inline AppLog& operator<< (Ident &ident)
00434 {
00435 open(ident.c_str());
00436 return *this;
00437 }
00438
00439
00444 inline AppLog &warn(void)
00445 {return operator()(Slog::levelWarning);}
00446
00451 AppLog &error(void)
00452 { return operator()(Slog::levelError);}
00453
00458 inline AppLog &debug(void)
00459 {return operator()(Slog::levelDebug);}
00460
00465 inline AppLog &emerg(void)
00466 {return operator()(Slog::levelEmergency);}
00467
00472 inline AppLog &alert(void)
00473 {return operator()(Slog::levelAlert);}
00474
00479 inline AppLog &critical(void)
00480 {return operator()(Slog::levelCritical);}
00481
00486 inline AppLog ¬ice(void)
00487 {return operator()(Slog::levelNotice);}
00488
00493 inline AppLog &info(void)
00494 {return operator()(Slog::levelInfo);}
00495
00511 static Slog::Level levelTranslate(string name)
00512 {
00513 map<string, Slog::Level>::iterator it = assoc->find(name);
00514
00515 return (it != assoc->end()) ? it->second : Slog::levelEmergency;
00516 }
00517
00518 };
00519
00525 __EXPORT inline AppLog &debug(AppLog& sl)
00526 {return sl.operator()(Slog::levelDebug);}
00527
00533 __EXPORT inline AppLog &warn(AppLog& sl)
00534 {return sl.operator()(Slog::levelWarning);}
00535
00541 __EXPORT inline AppLog &error(AppLog& sl)
00542 { return sl.operator()(Slog::levelError);}
00543
00549 __EXPORT inline AppLog &emerg(AppLog& sl)
00550 {return sl.operator()(Slog::levelEmergency);}
00551
00557 __EXPORT inline AppLog &alert(AppLog& sl)
00558 {return sl.operator()(Slog::levelAlert);}
00559
00565 __EXPORT inline AppLog &critical(AppLog& sl)
00566 {return sl.operator()(Slog::levelCritical);}
00567
00573 __EXPORT inline AppLog ¬ice(AppLog& sl)
00574 {return sl.operator()(Slog::levelNotice);}
00575
00581 __EXPORT inline AppLog &info(AppLog& sl)
00582 {return sl.operator()(Slog::levelInfo);}
00583
00587 __EXPORT extern AppLog alog;
00588
00589 #ifdef CCXX_NAMESPACES
00590 }
00591 #endif
00592
00593 #endif //___APPLOG_H___