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