-
Notifications
You must be signed in to change notification settings - Fork 18
/
logger.h
33 lines (29 loc) · 843 Bytes
/
logger.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
#pragma once
#include <stdio.h>
#include <stdarg.h>
#include <string>
class Logger{
private:
const static std::string level_name[];
public:
const static int ALL = 0;
const static int DEBUG = 1;
const static int INFO = 2;
const static int WARN = 3;
const static int ERROR = 4;
static int log_level;
static void log(int level, const char* format,...){
if(level < log_level || level > 4 || level < 0)
return;
FILE* stream = stdout;
if(level >= 3)
stream = stderr;
fprintf(stream,"[%s] ",level_name[level].c_str());
va_list args;
va_start(args,format);
vfprintf(stream,format,args);
va_end(args);
}
};
const std::string Logger::level_name[] = {"ALL","DEBUG","INFO","WARN","ERROR"};
int Logger::log_level = Logger::ALL;