File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ //
2+ // Created by atticus on 1/14/16.
3+ //
4+
5+ #include < unistd.h>
6+ #include < string.h>
7+ #include < mutex>
8+ #include < iostream>
9+ #include " LoggingSingleton.h"
10+
11+ std::mutex mutex;
12+
13+ LoggingSingleton::LoggingSingleton ()
14+ {
15+ std::cout << " Creating LoggingSingleton instance" <<std::endl;
16+ }
17+
18+ LoggingSingleton* LoggingSingleton::GetInstance ()
19+ {
20+ static LoggingSingleton pSingleton;
21+ return &pSingleton;
22+ }
23+
24+ void LoggingSingleton::log (int logFileDescriptor, const char * cFullMessage){
25+ mutex.lock ();
26+ write (logFileDescriptor, cFullMessage, strlen (cFullMessage));
27+ mutex.unlock ();
28+ }
29+
Original file line number Diff line number Diff line change 1+ //
2+ // Created by atticus on 1/14/16.
3+ //
4+
5+ #ifndef HACKTTP_LOGGINGSINGLETON_H
6+ #define HACKTTP_LOGGINGSINGLETON_H
7+
8+
9+ class LoggingSingleton {
10+ public:
11+ static LoggingSingleton* GetInstance ();
12+ void log (int logFileDescriptor, const char * cFullMessage);
13+ private:
14+ LoggingSingleton ();
15+ static LoggingSingleton* pSingleton;
16+ };
17+
18+
19+ #endif // HACKTTP_LOGGINGSINGLETON_H
You can’t perform that action at this time.
0 commit comments