forked from sl950313/SEDA-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.h
60 lines (52 loc) · 1.15 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
#ifndef _LOG_H
#define _LOG_H
#include <string.h>
#include <string>
#include <stdlib.h>
#include <stdarg.h>
#include "job_queue.h"
#include "marcos.h"
enum {
ERROR = 1,
INFO = 2,
DEBUG = 3
};
struct async_log_content {
char log_content[LOG_LEN];
unsigned int len_content;
async_log_content() {
memset(log_content, 0, LOG_LEN);
len_content = 0;
}
};
class LogUtil {
public:
LogUtil();
~LogUtil();
LogUtil(std::string _log_output, int _log_level);
void error(std::string _error);
void debug(std::string _debug);
void info(std::string _info);
static void error(const char *fmt, ...);
static void debug(const char *fmt, ...);
static void info(const char *fmt, ...);
bool set_async(bool async);
void stop();
private:
int init();
void make_message(const char *fmt, ...);
const char *log_output;
static int output_fd;
int log_level;
static void write_log(std::string log);
bool running;
/*
* for async logging
*/
static pthread_mutex_t async_lock;
static int is_async;
pthread_t log_pid;
static task_queue *tq;
static void *log_from_queue(void *);
};
#endif //