-
Notifications
You must be signed in to change notification settings - Fork 5
/
Log.h
106 lines (89 loc) · 1.8 KB
/
Log.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifndef galileo_log_h
#define galileo_log_h
#include <math.h>
#include <signal.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <string>
#include "net/IPaddr.h"
#include "net/Udp.h"
typedef enum _LogLevel {
LEVEL_DEBUG = 0,
LEVEL_INFO = 1,
LEVEL_ERROR = 2
} LogLevel;
/**
* Log class
*/
class Log {
public:
/**
* Log to DEBUG level
* @param s String or printf model
*/
static void d(const char *s, ...);
/**
* Log to INFO level
* @param s String or printf model
*/
static void i(const char *s, ...);
/**
* Log to ERROR level
* @param s String or printf model
*/
static void e(const char *s, ...);
/**
* Get configured SYSLOG
* @return SYSLOG ip address
*/
static IPaddr getSyslogServer();
/**
* Set log level
* @param level New log level
*/
static void setLogLevel(LogLevel level);
/**
* Set SYSLOG Server
* @param ipaddr New SYSLOG ipaddr
*/
static void setSyslogServer(IPaddr ipaddr);
/**
* Switch to a new log file
* @param logFilePath New log file path
*/
static void setLogFile(std::string logFilePath);
/**
* Switch to a new log file
* @param logFilePath New log file path
*/
static void setLogFile(const char* logFilePath);
/**
* Enable log to STDOUT
* @param b If true, log will be written also to STDOUT
*/
static void enableStdoutDebug(bool b);
/**
* Update settings from config
*/
static void updateFromConfig();
/**
* Rotate log
*/
static void rotate();
/**
* Close log class
*/
static void close();
private:
static void log(LogLevel, const char *, va_list argptr);
static std::string getDateTime();
static IPaddr syslogServer;
static bool syslogEnabled;
static Udp syslogUdp;
static std::string logFilePath;
static FILE *logFile;
static LogLevel logLevel;
static bool stdoutDebug;
};
#endif