-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logging.h
50 lines (47 loc) · 1.53 KB
/
Logging.h
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
41
42
43
44
45
46
47
48
49
50
#ifndef __LOGGING_H
#define __LOGGING_H
#include <string>
#include <stdint.h>
#include "Buffer.h"
class LogStream {
public:
LogStream(const char * file, int lineno, int logLevel);
LogStream & operator << (float);
LogStream & operator << (double);
LogStream & operator << (int64_t);
LogStream & operator << (uint64_t);
LogStream & operator << (int32_t);
LogStream & operator << (uint32_t);
LogStream & operator << (int16_t);
LogStream & operator << (uint16_t);
~LogStream();
LogStream & operator << (const char* str) ;
//LogStream & operator << (const void* ptr)
//{
// printf("%x", reinterpret_cast<uintptr_t>(ptr));
// return *this;
//}
LogStream & operator << (char ch) {
buffer_.append(ch);
return *this;
}
LogStream & operator << (const std::string & s) {
//printf("%s", s.c_str());
buffer_.append(s.c_str(),s.size());
return *this;
}
enum {LogTrace, LogDebug, LogVerbose};
static void setLevel(int l) { level = l; }
static int getLevel() { return level; }
private:
template < class T> void printIntegral(T);
static int level;
Buffer buffer_;
};
#define LOG_DEBUG if (LogStream::getLevel() >= LogStream::LogDebug)\
LogStream(__FILE__, __LINE__, LogStream::LogDebug)
#define LOG_VERBOSE if (LogStream::getLevel() >= LogStream::LogVerbose)\
LogStream(__FILE__, __LINE__, LogStream::LogVerbose)
#define LOG_TRACE if (LogStream::getLevel() >= LogStream::LogTrace)\
LogStream(__FILE__, __LINE__, LogStream::LogTrace)
#endif// __LOGGING_H