-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathDlepLogger.h
79 lines (70 loc) · 2.05 KB
/
DlepLogger.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Dynamic Link Exchange Protocol (DLEP)
*
* Copyright (C) 2013, 2018, 2019 Massachusetts Institute of Technology
*/
#ifndef _DLEP_LOGGER_
#define _DLEP_LOGGER_
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <strings.h>
#include <time.h>
#include <sys/time.h>
#include <ctype.h>
#include <assert.h>
#include <map>
#include <boost/thread/mutex.hpp>
namespace LLDLEP
{
namespace internal
{
#define MAX_LEVEL 5
#define MIN_LEVEL 1
#define DLEP_LOG_FATAL 5
#define DLEP_LOG_ERROR 4
#define DLEP_LOG_NOTICE 3
#define DLEP_LOG_INFO 2
#define DLEP_LOG_DEBUG 1
#define DEBUG_FILE __FILE__
#define DEBUG_FUNCTION __func__
#define DEBUG_LINE __LINE__
#define DEBUG_DATE __DATE__
#define DEBUG_TIME __TIME__
class DlepLogger
{
public:
explicit DlepLogger(const std::string & filename, unsigned int level);
~DlepLogger();
void log(unsigned int level, std::ostringstream & msg);
void set_log_level(unsigned int level);
void set_log_file(const std::string & filename);
private:
unsigned int log_level;
unsigned int clamp_log_level(unsigned int level);
std::ofstream logfile;
std::string time_string_get();
std::map <int, std::string> level_name = {
{ DLEP_LOG_DEBUG, "DEBUG: " },
{ DLEP_LOG_INFO, "INFO: " },
{ DLEP_LOG_NOTICE, "NOTICE:" },
{ DLEP_LOG_ERROR, "ERROR: " },
{ DLEP_LOG_FATAL, "FATAL: " },
};
boost::mutex mutex;
};
typedef boost::shared_ptr<DlepLogger> DlepLoggerPtr;
#define LOG(_level, _msg) { \
std::ostringstream m; \
m << DEBUG_FILE << ":" << DEBUG_LINE << ":" << DEBUG_FUNCTION << \
"(): " << (_msg).str() ; \
logger->log(_level, m); \
(_msg).str(""); \
}
} // namespace internal
} // namespace LLDLEP
#endif // _DLEP_LOGGER_