Bayonne2 / Common C++ 2 Framework: applog.h Source File

Bayonne2 / Common C++ 2 Framework
applog.h
Go to the documentation of this file.
1 // Copyright (C) 2005-2010 Angelo Naselli, Penta Engineering s.r.l.
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License for more details.
11 //
12 // You should have received a copy of the GNU General Public License
13 // along with this program; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 //
16 // As a special exception, you may use this file as part of a free software
17 // library without restriction. Specifically, if other files instantiate
18 // templates or use macros or inline functions from this file, or you compile
19 // this file and link it with other files to produce an executable, this
20 // file does not by itself cause the resulting executable to be covered by
21 // the GNU General Public License. This exception does not however
22 // invalidate any other reasons why the executable file might be covered by
23 // the GNU General Public License.
24 //
25 // This exception applies only to the code released under the name GNU
26 // Common C++. If you copy code from other releases into a copy of GNU
27 // Common C++, as the General Public License permits, the exception does
28 // not apply to the code that you add in this way. To avoid misleading
29 // anyone as to the status of such modified files, you must delete
30 // this exception notice from them.
31 //
32 // If you write modifications of your own for GNU Common C++, it is your choice
33 // whether to permit this exception to apply to your modifications.
34 // If you do not wish that, delete this exception notice.
35 //
36 
43 #ifndef ___APPLOG_H___
44 #define ___APPLOG_H___
45 
46 #ifndef CCXX_SLOG_H_
47 #include <cc++/slog.h>
48 #endif
49 
50 #include <cc++/exception.h>
51 
52 #include <string>
53 #include <sstream>
54 #include <iostream>
55 #include <map>
56 
57 #ifdef CCXX_NAMESPACES
58 using namespace std;
59 
60 namespace ost
61 {
62 #endif
63 
71  class __EXPORT HEXdump
72 {
73  protected:
77   std::string _str;
78 
79  public:
80  // max_len: max number of bytes to be printed. 0 prints all.
89  HEXdump(const unsigned char *buffer, int buff_len, int max_len = 200);
90 
94   virtual ~HEXdump() { _str = string();}
95 
100   const char * c_str() const
101 {
102  return _str.c_str();
103  }
104 
108   std::string str()
109  {
110  return _str;
111  }
112 
118   friend std::ostream& operator<< (std::ostream& out, const HEXdump &hd)
119  {
120  out << hd.c_str();
121  return out;
122  }
123 
124 };
125 
126 #ifdef CCXX_EXCEPTIONS
127 
131 class __EXPORT AppLogException : public ost::Exception
132 {
133  public:
138  AppLogException(const std::string &what_arg) : ost::Exception(what_arg) {};
139 
140 };
141 #endif
142 
143 class AppLogPrivate;
144 
173  class __EXPORT AppLog : protected streambuf, public ostream
174 {
175  protected:
176  // d pointer
177   AppLogPrivate *d;
178  void writeLog(bool endOfLine = true);
179   static map<string, Slog::Level> *assoc;
180 
181  public:
185   class __EXPORT Ident
186  {
187  private:
188   std::string _ident;
189  public:
190 
194   Ident() {};
195 
199   ~Ident() {};
200 
204   Ident(Ident& id) {_ident = id._ident;}
205 
209   Ident(const char *str) : _ident(str) {};
210 
214   std::string& str() {return _ident;}
215 
219   Ident& operator= (std::string &st) {_ident = st; return *this;}
220 
224   Ident& operator= (const char str[]) {_ident = str; return *this;}
225 
229   const char* c_str() {return _ident.c_str();}
230  };
231 
232 #ifndef WIN32
233 
240  AppLog(const char* logFileName = NULL, bool logDirectly = false , bool usePipe = false);
241 #else
242 
248  AppLog(const char* logFileName = NULL, bool logDirectly = false);
249 #endif
250 
253  virtual ~AppLog();
254 
259  void subscribe();
260 
264  void unsubscribe();
265 
266 #ifndef WIN32
267 
274  void logFileName(const char* FileName, bool logDirectly = false, bool usePipe = false);
275 #else
276 
282  void logFileName(const char* FileName, bool logDirectly = false);
283 #endif
284 
287  void close(void);
288 
293  void level(Slog::Level enable);
294 
299  void clogEnable(bool en = true);
300 
305  void slogEnable(bool en = true);
306 
312  void identLevel(const char *ident, Slog::Level level);
313 
318  void open(const char *ident);
319 
325  virtual int overflow(int c);
326 
330  virtual int sync();
331 
332 #ifdef HAVE_SNPRINTF
333 
338  void emerg(const char *format, ...);
339 
344  void alert(const char *format, ...);
345 
350  void critical(const char *format, ...);
351 
356  void error(const char *format, ...);
357 
362  void warn(const char *format, ...);
363 
368  void notice(const char *format, ...);
369 
374  void info(const char *format, ...);
375 
380  void debug(const char *format, ...);
381 #endif
382 
389  AppLog &operator()(const char *ident, Slog::Level level = Slog::levelError);
390 
396   inline AppLog& operator()(Ident &ident)
397  {
398  open(ident.c_str());
399  return *this;
400  }
401 
407  AppLog &operator()(Slog::Level level);
408 
414  AppLog& operator<< (AppLog& (*pfManipulator)(AppLog&));
415 
421  AppLog& operator<< (ostream& (*pfManipulator)(ostream&));
422 
423   friend ostream& operator << (ostream &out, AppLog & al)
424  {
425  return al;
426  }
427 
433   inline AppLog& operator<< (Ident &ident)
434  {
435  open(ident.c_str());
436  return *this;
437  }
438 
439 
444   inline AppLog &warn(void)
445  {return operator()(Slog::levelWarning);}
446 
451   AppLog &error(void)
452  { return operator()(Slog::levelError);}
453 
458   inline AppLog &debug(void)
459  {return operator()(Slog::levelDebug);}
460 
465   inline AppLog &emerg(void)
466  {return operator()(Slog::levelEmergency);}
467 
472   inline AppLog &alert(void)
473  {return operator()(Slog::levelAlert);}
474 
479   inline AppLog &critical(void)
480  {return operator()(Slog::levelCritical);}
481 
486   inline AppLog &notice(void)
487  {return operator()(Slog::levelNotice);}
488 
493   inline AppLog &info(void)
494  {return operator()(Slog::levelInfo);}
495 
511   static Slog::Level levelTranslate(string name)
512  {
513  map<string, Slog::Level>::iterator it = assoc->find(name);
514 
515  return (it != assoc->end()) ? it->second : Slog::levelEmergency;
516  }
517 
518 };
519 
525  __EXPORT inline AppLog &debug(AppLog& sl)
526 {return sl.operator()(Slog::levelDebug);}
527 
533  __EXPORT inline AppLog &warn(AppLog& sl)
534 {return sl.operator()(Slog::levelWarning);}
535 
541  __EXPORT inline AppLog &error(AppLog& sl)
542 { return sl.operator()(Slog::levelError);}
543 
549  __EXPORT inline AppLog &emerg(AppLog& sl)
550 {return sl.operator()(Slog::levelEmergency);}
551 
557  __EXPORT inline AppLog &alert(AppLog& sl)
558 {return sl.operator()(Slog::levelAlert);}
559 
565  __EXPORT inline AppLog &critical(AppLog& sl)
566 {return sl.operator()(Slog::levelCritical);}
567 
573  __EXPORT inline AppLog &notice(AppLog& sl)
574 {return sl.operator()(Slog::levelNotice);}
575 
581  __EXPORT inline AppLog &info(AppLog& sl)
582 {return sl.operator()(Slog::levelInfo);}
583 
587 __EXPORT extern AppLog alog;
588 
589 #ifdef CCXX_NAMESPACES
590 } //namespace
591 #endif
592 
593 #endif //___APPLOG_H___
AppLog::error
AppLog & error(void)
error level
Definition: applog.h:451
HEXdump::str
std::string str()
string cast provided for conveneince.
Definition: applog.h:108
AppLog::levelTranslate
static Slog::Level levelTranslate(string name)
Translates level from string to Slog::Level, useful for configuration files for instance.
Definition: applog.h:511
AppLog::Ident::str
std::string & str()
std::string cast.
Definition: applog.h:214
debug
__EXPORT AppLog & debug(AppLog &sl)
Manipulator for debug level.
Definition: applog.h:525
error
__EXPORT AppLog & error(AppLog &sl)
Manipulator for error level.
Definition: applog.h:541
AppLog::Ident::c_str
const char * c_str()
const char* cast provided for conveneince.
Definition: applog.h:229
info
__EXPORT AppLog & info(AppLog &sl)
Manipulator for info level.
Definition: applog.h:581
AppLog::Ident::Ident
Ident(Ident &id)
Copy constructor.
Definition: applog.h:204
AppLog::Ident::Ident
Ident(const char *str)
const char* constructor, provided for convenience.
Definition: applog.h:209
AppLog::assoc
static map< string, Slog::Level > * assoc
Definition: applog.h:179
exception.h
GNU Common C++ exception model base classes.
AppLog::warn
AppLog & warn(void)
warn level
Definition: applog.h:444
operator<<
__EXPORT std::ostream & operator<<(std::ostream &os, const IPV4Address &ia)
AppLog::critical
AppLog & critical(void)
critical level
Definition: applog.h:479
HEXdump
Produces a dump of a buffer in a hexdump way with its code Ascii translation and relative buffer addr...
Definition: applog.h:71
Slog::Level
Level
Definition: slog.h:123
HEXdump::c_str
const char * c_str() const
const char* cast provided for conveneince.
Definition: applog.h:100
emerg
__EXPORT AppLog & emerg(AppLog &sl)
Manipulator for emerg level.
Definition: applog.h:549
AppLog::Ident::_ident
std::string _ident
Definition: applog.h:188
AppLog::debug
AppLog & debug(void)
debug level
Definition: applog.h:458
notice
__EXPORT AppLog & notice(AppLog &sl)
Manipulator for notice level.
Definition: applog.h:573
HEXdump::~HEXdump
virtual ~HEXdump()
HEXdump destructor.
Definition: applog.h:94
AppLog::emerg
AppLog & emerg(void)
emerg level
Definition: applog.h:465
AppLog::Ident
Ident class that represents module name.
Definition: applog.h:185
AppLog::Ident::Ident
Ident()
Constructor.
Definition: applog.h:194
AppLog::operator()
AppLog & operator()(Ident &ident)
operator to change ident
Definition: applog.h:396
__EXPORT
#define __EXPORT
Definition: audio2.h:51
alert
__EXPORT AppLog & alert(AppLog &sl)
Manipulator for alert level.
Definition: applog.h:557
alog
__EXPORT AppLog alog
alog global log stream definition
AppLog::d
AppLogPrivate * d
Definition: applog.h:177
slog.h
System logging facilities abstraction.
AppLog::notice
AppLog & notice(void)
notice level
Definition: applog.h:486
HEXdump::_str
std::string _str
output string
Definition: applog.h:77
AppLog
Application logger is a class that implements a logger that can be used by applications to save log f...
Definition: applog.h:173
AppLog::info
AppLog & info(void)
info level
Definition: applog.h:493
warn
__EXPORT AppLog & warn(AppLog &sl)
Manipulator for warn level.
Definition: applog.h:533
critical
__EXPORT AppLog & critical(AppLog &sl)
Manipulator for critical level.
Definition: applog.h:565
AppLog::alert
AppLog & alert(void)
alert level
Definition: applog.h:472
AppLog::Ident::~Ident
~Ident()
Desctructor.
Definition: applog.h:199

Generated on Dec 21, 2017 for commoncpp2-1.8.1, ccrtp-1.7.2, libzrtpcpp-2.3.4, ccscript3-1.1.7, ccaudio2-1.0.0 and bayonne2-2.3.2 (after installation in /usr/local/) by   doxygen 1.8.6

AltStyle によって変換されたページ (->オリジナル) /