forked from 0xmalloc/c-log
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.h
More file actions
52 lines (45 loc) · 1.29 KB
/
log.h
File metadata and controls
52 lines (45 loc) · 1.29 KB
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
#ifndef _MACRO_LogModule
#define _MACRO_LogModule
#include <stdio.h>
#include <pthread.h>
#include "macro_define.h"
typedef enum LogLevel {
LL_DEBUG = 1,
LL_TRACE = 2,
LL_NOTICE = 3,
LL_WARNING = 4,
LL_ERROR = 5,
}LogLevel;
class LogWriter {
public:
LogWriter();
~LogWriter();
bool loginit(LogLevel l, const char *filelocation, bool verbose, bool append = true, bool issync = false);
bool log(LogLevel l, const char *logformat, ...)__attribute__((format(printf,3,4)));
LogLevel getlevel();
bool logclose();
void removeConsole();
public:
const static unsigned int M_LOG_PATH_LEN = 250;
private:
const char* logLevelToString(LogLevel l);
bool checklevel(LogLevel l);
int premakestr(char* m_buffer, LogLevel l);
bool write(char *pbuffer, int len);
private:
const static unsigned int M_LOG_BUFFSIZE = 1024*1024*4;
const static unsigned int M_SYS_BUFFSIZE = 1024*1024*8;
const static unsigned int M_LOG_MODULE_LEN = 32;
enum LogLevel m_system_level;
FILE* fp;
bool m_issync;
bool m_isappend;
bool m_verbose;
char m_filelocation[M_LOG_PATH_LEN];
pthread_mutex_t m_mutex;
static __thread char m_buffer[M_LOG_BUFFSIZE];
};
extern LogWriter WARN_W;
extern LogWriter INFO_W;
bool logInit(LogLevel l, const char* modulename, const char* logdir, bool verbose);
#endif