42 #ifndef COMMONCPP_APPLOG_H_ 43 #define COMMONCPP_APPLOG_H_ 45 #ifndef COMMONCPP_CONFIG_H_ 46 #include <commoncpp/config.h> 49 #ifndef COMMONCPP_SLOG_H_ 53 #ifndef COMMONCPP_EXCEPTION_H_ 73 class __EXPORT HEXdump
91 HEXdump(
const uint8_t *buffer,
int buff_len,
int max_len = 200);
96 virtual ~HEXdump() { _str = string();}
102 const char * c_str()
const {
118 friend std::ostream& operator<< (std::ostream& out,
const HEXdump &hd)
126 #ifdef CCXX_EXCEPTIONS 131 class __EXPORT AppLogException :
public ost::Exception
138 AppLogException(
const char *what_arg) :
ost::Exception(what_arg) {}
143 class __LOCAL AppLogPrivate;
173 class __EXPORT AppLog :
protected streambuf,
public ostream
178 void writeLog(
bool endOfLine =
true);
179 static std::map<string, Slog::Level> *assoc;
204 Ident(Ident&
id) {_ident =
id._ident;}
209 Ident(
const char *str) : _ident(str) {}
214 std::string& str() {
return _ident;}
219 Ident& operator= (std::string &st) {_ident = st;
return *
this;}
224 Ident& operator= (
const char str[]) {_ident = str;
return *
this;}
229 const char* c_str()
const {
return _ident.c_str();}
240 AppLog(
const char* logFileName = NULL,
bool logDirectly =
false ,
bool usePipe =
false);
248 AppLog(
const char* logFileName = NULL,
bool logDirectly =
false);
274 void logFileName(
const char* FileName,
bool logDirectly =
false,
bool usePipe =
false);
282 void logFileName(
const char* FileName,
bool logDirectly =
false);
293 void level(Slog::Level enable);
299 void clogEnable(
bool en =
true);
305 void slogEnable(
bool en =
true);
312 void identLevel(
const char *ident, Slog::Level level);
318 void open(
const char *ident);
325 virtual int overflow(
int c);
336 void emerg(
const char *format, ...);
342 void alert(
const char *format, ...);
348 void critical(
const char *format, ...);
354 void error(
const char *format, ...);
360 void warn(
const char *format, ...);
366 void notice(
const char *format, ...);
372 void info(
const char *format, ...);
378 void debug(
const char *format, ...);
386 AppLog &operator()(
const char *ident, Slog::Level level = Slog::levelError);
393 inline AppLog& operator()(
const Ident &ident) {
403 AppLog &operator()(Slog::Level level);
410 AppLog& operator<< (AppLog& (*pfManipulator)(AppLog&));
417 AppLog& operator<< (ostream& (*pfManipulator)(ostream&));
419 friend ostream& operator << (ostream &os, AppLog & al)
429 inline AppLog& operator<< (Ident &ident)
440 inline AppLog &warn(
void)
441 {
return operator()(Slog::levelWarning);}
448 {
return operator()(Slog::levelError);}
454 inline AppLog &debug(
void)
455 {
return operator()(Slog::levelDebug);}
461 inline AppLog &emerg(
void)
462 {
return operator()(Slog::levelEmergency);}
468 inline AppLog &alert(
void)
469 {
return operator()(Slog::levelAlert);}
475 inline AppLog &critical(
void)
476 {
return operator()(Slog::levelCritical);}
482 inline AppLog ¬ice(
void)
483 {
return operator()(Slog::levelNotice);}
489 inline AppLog &info(
void)
490 {
return operator()(Slog::levelInfo);}
507 static Slog::Level levelTranslate(
string name)
509 std::map<string, Slog::Level>::iterator it = assoc->find(name);
510 return (it != assoc->end()) ? it->second : Slog::levelEmergency;
520 __EXPORT
inline AppLog &debug(AppLog& sl)
521 {
return sl.operator()(Slog::levelDebug);}
528 __EXPORT
inline AppLog &warn(AppLog& sl)
529 {
return sl.operator()(Slog::levelWarning);}
536 __EXPORT
inline AppLog &error(AppLog& sl)
537 {
return sl.operator()(Slog::levelError);}
544 __EXPORT
inline AppLog &emerg(AppLog& sl)
545 {
return sl.operator()(Slog::levelEmergency);}
552 __EXPORT
inline AppLog &alert(AppLog& sl)
553 {
return sl.operator()(Slog::levelAlert);}
560 __EXPORT
inline AppLog &critical(AppLog& sl)
561 {
return sl.operator()(Slog::levelCritical);}
568 __EXPORT
inline AppLog ¬ice(AppLog& sl)
569 {
return sl.operator()(Slog::levelNotice);}
576 __EXPORT
inline AppLog &info(AppLog& sl)
577 {
return sl.operator()(Slog::levelInfo);}
582 __EXPORT
extern AppLog alog;
586 #endif //___APPLOG_H___
System logging facilities abstraction.
GNU Common C++ exception model base classes.