libnavajo
web server for static and dynamic pages developement in C++
LogRecorder.hh
Go to the documentation of this file.
1 //********************************************************
12 //********************************************************
13 
14 #ifndef LOGRECORDER_HH_
15 #define LOGRECORDER_HH_
16 
17 #include <iostream>
18 #include <sstream>
19 #include <fstream>
20 #include <string>
21 #include <list>
22 #include <set>
23 #include "libnavajo/LogOutput.hh"
24 
25 #define NVJ_LOG LogRecorder::getInstance()
26 
27 
28 
33  {
34 
35  pthread_mutex_t log_mutex;
36  bool debugMode;
37  std::set<std::string> uniqLog; // Only one entry !
38 
39  public:
40 
45  inline static LogRecorder *getInstance()
46  {
47  if (theLogRecorder == NULL)
49  return theLogRecorder;
50  };
51 
56  static void freeInstance()
57  {
58  if (theLogRecorder != NULL)
59  delete theLogRecorder;
60 
61  theLogRecorder=NULL;
62  }
63  void setDebugMode(bool d=true) { debugMode=d; };
64  void addLogOutput(LogOutput *);
65  void removeLogOutputs();
66  void append(const NvjLogSeverity& l, const std::string& msg, const std::string& details="");
67  inline void appendUniq(const NvjLogSeverity& l, const std::string& msg, const std::string& details="")
68  {
69  std::set<std::string>::iterator it;
70  it=uniqLog.find(msg+details);
71  if (it==uniqLog.end())
72  {
73  uniqLog.insert(msg+details);
74  append(l, msg, details);
75  }
76  };
77  inline void initUniq() { uniqLog.clear(); } ;
78 
79  protected:
80  LogRecorder();
81  ~LogRecorder();
82  std::string getDateStr();
83 
84  std::list<LogOutput *> logOutputsList_;
85 
87 
88  };
89 
90 
91 #endif
LogRecorder()
Definition: LogRecorder.cc:109
Generic log output (abstract class)
void removeLogOutputs()
Definition: LogRecorder.cc:94
static void freeInstance()
Definition: LogRecorder.hh:56
void addLogOutput(LogOutput *)
Definition: LogRecorder.cc:84
void append(const NvjLogSeverity &l, const std::string &msg, const std::string &details="")
Definition: LogRecorder.cc:52
Definition: LogRecorder.hh:32
static LogRecorder * theLogRecorder
Definition: LogRecorder.hh:86
~LogRecorder()
Definition: LogRecorder.cc:119
std::string getDateStr()
Definition: LogRecorder.cc:30
static LogRecorder * getInstance()
Definition: LogRecorder.hh:45
Definition: LogOutput.hh:30