CARDS 2.4.87
Package manager for the NuTyX GNU/Linux distribution
cards_log.h
1 /*
2  * cards_log.h
3  *
4  * Copyright 2018 Gianni Peschiutta <artemia@nutyx.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  *
21  *
22  */
23 
24 #ifndef CARDS_LOG_H
25 #define CARDS_LOG_H
26 
27 #include <string>
28 #include <algorithm>
29 #include <sstream>
30 #include <vector>
31 #include <mutex>
32 #include <thread>
33 
34 #include "cards_event_handler.h"
35 
36 #ifndef _
37  #define _(T) std::string(T)
38 #endif
39 #define MAX_BUFFER 50
40 
41 namespace cards
42 {
43  using namespace std;
44  enum CL_DEBUG_LEVEL
45  {
46  LEVEL_INFO,
47  LEVEL_WARNING,
48  LEVEL_DEBUG,
49  LEVEL_ERROR,
50  };
51 
52  class CLogger
53  {
54  private:
55  CLogger();
56  virtual ~CLogger(){}
57  static CLogger* m_ptLogger;
58  vector<string> m_ArrMessages;
59  vector<CEventHandler*> m_ArrSubscribers;
60  mutex m_ArrMutex;
61  thread::id m_ThreadId;
62  void sendToSubscribers(const string& pMessage);
63 
64  public:
65  static CLogger* instance();
66  static void kill();
67  void log ( const string& pMessage,
68  CL_DEBUG_LEVEL pLevel=LEVEL_INFO);
69  static void loopCallback(void*);
70  void subscribe (CEventHandler* pSubscriber);
71  void unSubscribe (CEventHandler* pSubscriber);
72  };
73 }
74 
75 #endif
Definition: cards_event_handler.h:61
Definition: cards_log.h:52
Definition: cards_client.cxx:26