-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathDebug.cpp
45 lines (35 loc) · 857 Bytes
/
Debug.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <time.h>
#include <mutex>
#include <map>
#define __DBG_CLASS
#include "Debug.h"
#ifdef ANDROID
#include <android/log.h>
#endif
pthread_t Debug::mMainThread = 0;
bool Debug::mStoreLog = false;
std::string Debug::mLog = std::string();
std::mutex Debug::mLogMutex;
std::ofstream Debug::mLogFile;
Debug::Level Debug::mDebugLevel = Debug::Warning;
bool Debug::mColors = true;
void Debug::log( int level, const std::string& s ) {
#ifdef ANDROID
__android_log_print( ANDROID_LOG_DEBUG + ( Level::Verbose - level ), "luaserver", "%s", s.c_str() );
#else
if ( level <= Debug::Warning ) {
std::cerr << s << std::flush;
} else {
std::cout << s << std::flush;
}
#endif
if ( mStoreLog ) {
mLogMutex.lock();
mLog += s;
mLogMutex.unlock();
}
if ( mLogFile.is_open() ) {
mLogFile.write( s.c_str(), s.size() );
mLogFile.flush();
}
}